Last active
January 1, 2016 23:59
-
-
Save LiamChapman/8219834 to your computer and use it in GitHub Desktop.
A quick shorthand for selecting elements using the native css selector in javascript e.g. document.find('#foo'); Need to update it to do some chaining
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
| Document.prototype.find = function (query) { | |
| if (document.querySelectorAll) { | |
| var query = this.querySelectorAll(query); | |
| if (query.length == 1) | |
| return query[0]; | |
| else | |
| return query; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment