Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active May 4, 2017 16:54
Show Gist options
  • Save danielpataki/573157234d4d0b3688bb8bb20647b796 to your computer and use it in GitHub Desktop.
Save danielpataki/573157234d4d0b3688bb8bb20647b796 to your computer and use it in GitHub Desktop.
Vanilla Javascript
<ul id="myList">
<li>List Item One</li>
<li>List Item Two</li>
</ul>
// jQuery Version
var firstElement = jQuery('#myList li:first');
var nextElement = firstElement.next();
// Vanilla Javascript
var firstElement = document.getElementById('myList').getElementsByTagName('li')[0];
var nextElement = firstElement.nextSibling.nextSibling;
// jQuery Version
$('#post a').addClass('postLink');
// Vanilla Javascript
var links = document.getElementById('my-element').getElementsByTagName('a');
for (i = 0; i < links.length; ++i) {
links[0].className = 'postLink';
}
// jQuery Version
$('#myElement').data('scale'); // Get
$('#myElement').data('scale', '10'); // Set
// Vanilla Javascript
document.getElementById('my-element').getAttribute('data-scale') // Get
document.getElementById('my-element').setAttribute('data-scale', '10') // Set
// jQuery Version
var element = $('#my-element');
var links = $('a.mylinks');
var articles = $('article');
// Vanilla Javascript
var element = document.getElementById('my-element');
var links = document.getElementsByClassName('mylinks');
var articles = document.getElementsByTagName('article');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment