Skip to content

Instantly share code, notes, and snippets.

@LiamChapman
Last active January 1, 2016 23:59
Show Gist options
  • Select an option

  • Save LiamChapman/8219834 to your computer and use it in GitHub Desktop.

Select an option

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
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