Skip to content

Instantly share code, notes, and snippets.

@bwll
Created January 4, 2017 00:18
Show Gist options
  • Save bwll/b40c6836c8a58984b0094829bae8070b to your computer and use it in GitHub Desktop.
Save bwll/b40c6836c8a58984b0094829bae8070b to your computer and use it in GitHub Desktop.
/*
* https://developer.mozilla.org/en-US/Add-ons/Code_snippets/QuerySelector
*/
function $ (selector, el) {
if (!el) {el = document;}
return el.querySelector(selector);
}
function $$ (selector, el) {
if (!el) {el = document;}
return el.querySelectorAll(selector);
// Note: the returned object is a NodeList.
// If you'd like to convert it to a Array for convenience, use this instead:
// return Array.prototype.slice.call(el.querySelectorAll(selector));
}
alert($('#myID').id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment