Last active
May 4, 2017 16:54
-
-
Save danielpataki/573157234d4d0b3688bb8bb20647b796 to your computer and use it in GitHub Desktop.
Vanilla Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul id="myList"> | |
<li>List Item One</li> | |
<li>List Item Two</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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