Last active
August 29, 2015 14:01
-
-
Save WebReflection/c92c8d9223449d23e09c to your computer and use it in GitHub Desktop.
A jQuery like function with :first built in optimization, will return an Array regardless it's one element search only for consistency.
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
| function $(CSS, parentNode) { | |
| // @link http://webreflection.blogspot.com/2014/05/134-bytes-for-optimized-and-very-basic.html | |
| var el = parentNode || document, | |
| first = CSS.lastIndexOf(':first') === CSS.length - 6, | |
| query = first ? | |
| el.querySelector(CSS.slice(0, -6)) : | |
| el.querySelectorAll(CSS); | |
| return first ? | |
| (query ? [query] : []) : | |
| Array.prototype.slice.call(query); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
examples