Skip to content

Instantly share code, notes, and snippets.

@zerostyle
Last active December 16, 2015 16:49
Show Gist options
  • Save zerostyle/5465964 to your computer and use it in GitHub Desktop.
Save zerostyle/5465964 to your computer and use it in GitHub Desktop.
Minimal css selector
/**
* Minimal CSS selector engine for modern browsers.
* @param {String} selector A string containing a selector expression.
* @param {Node=} opt_context The context to search within.
* @returns {Node|NodeList} An element or list of matched elements.
*/
window.$$ = function(selector, opt_context) {
var context = opt_context || document;
var results = context.querySelectorAll(selector);
return results.length > 1 ? results : results[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment