Created
September 27, 2015 21:37
-
-
Save innermond/6797cc6a73ae2c21c5e7 to your computer and use it in GitHub Desktop.
interesting bits of javascript
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
| // Returns first element that matches CSS selector {expr}. | |
| // Querying can optionally be restricted to {container}’s descendants | |
| function $(expr, container) { | |
| return typeof expr === "string"? (container || document).querySelector(expr) : expr || null; | |
| } | |
| // Returns all elements that match CSS selector {expr} as an array. | |
| // Querying can optionally be restricted to {container}’s descendants | |
| function $$(expr, container) { | |
| return [].slice.call((container || document).querySelectorAll(expr)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment