Last active
August 29, 2015 14:12
-
-
Save itsallrelative/b5570cd5ff7b4e4ecf0a to your computer and use it in GitHub Desktop.
Pure JavaScript solutions without jQuery
This file contains hidden or 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
| //Document Ready | |
| //jQuery | |
| $(document).ready(function(){ | |
| //other jQuery here | |
| }); | |
| //Good ol' fashion JS IE9+ | |
| document.addEventListener('DOMContentLoaded', function(){ | |
| }); |
This file contains hidden or 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
| //Event Listeners | |
| //No longer shall we use element.attachEvent!!! | |
| //jQuery | |
| var $thing = $('.some-element'); | |
| $thing.on('click', function(){ | |
| alert("You don't need no stinking jQuery!"); | |
| }); | |
| //vanilla.js | |
| var thing = document.querySelectorAll('.some-element'); | |
| thing.addEventListener("click",alertMessage,false); | |
| function alertMessage(){ | |
| alert("You don't need no stinking jQuery!"); | |
| } |
This file contains hidden or 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
| //Getting a DOM Element | |
| //jQuery | |
| var $thing = $('.some-element-with-a-class'); | |
| var $thing2 = $('#some-element-with-an-id'); | |
| var $thing3 = $('p'); //returns array of all p elements | |
| //The cross browser compatible IE9+ method | |
| var thing = document.querySelectorAll('.some-element-with-a-class'); | |
| var thing2 = document.getElementById('some-element-with-an-id'); | |
| var thing3 = document.getElementsByTagName('p'); //returns array of all p elements |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment