Skip to content

Instantly share code, notes, and snippets.

@juanbrujo
Created December 8, 2015 14:19
Show Gist options
  • Save juanbrujo/464f9d83af01645d32dd to your computer and use it in GitHub Desktop.
Save juanbrujo/464f9d83af01645d32dd to your computer and use it in GitHub Desktop.
Shortcut to get elements
// 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