Skip to content

Instantly share code, notes, and snippets.

@midned
Last active December 19, 2015 03:08
Show Gist options
  • Save midned/5887660 to your computer and use it in GitHub Desktop.
Save midned/5887660 to your computer and use it in GitHub Desktop.
function $(selector, context)
{
if (!(context instanceof Element)) {
context = document;
}
return context.querySelectorAll(selector);
}
// querySelectorAll() returns a NodeList object so we need to get the first one
parent = $('.parent', document.body)[0];
child1 = $('.child-1', parent)[0]; // parent is the context element (fast search)
child2 = $('.child-2')[0]; // will search in the entire document
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment