Created
December 8, 2015 14:19
-
-
Save juanbrujo/464f9d83af01645d32dd to your computer and use it in GitHub Desktop.
Shortcut to get elements
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
// Shortcut to get elements | |
var $ = function(element) { | |
if (element.charAt(0) === "#") { // If passed an ID... | |
return document.querySelector(element); // ... returns single element | |
} | |
return document.querySelectorAll(element); // Otherwise, returns a nodelist | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment