Last active
December 16, 2015 16:49
-
-
Save zerostyle/5465964 to your computer and use it in GitHub Desktop.
Minimal css selector
This file contains hidden or 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
/** | |
* 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