Skip to content

Instantly share code, notes, and snippets.

@spiralx
Forked from Raynos/select.js
Created February 21, 2018 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spiralx/524b3a522db7e2fd02e67518c843e102 to your computer and use it in GitHub Desktop.
Save spiralx/524b3a522db7e2fd02e67518c843e102 to your computer and use it in GitHub Desktop.
tiny select. Selecting has never been so awesome \o/
// Pretty fast - http://jsperf.com/select-vs-natives-vs-jquery
/*
By, shortcuts for getting elements.
*/
var By = {
id: function (id) { return document.getElementById(id) },
tag: function (tag, context) {
return (context || document).getElementsByTagName(tag)
},
"class": function (klass, context) {
return (context || document).getElementsByClassName(klass)
},
name: function (name) { return document.getElementsByName(name) },
qsa: function (query, context) {
return (context || document).querySelectorAll(query)
},
qs: function (query, context) {
return (context || document).querySelector(query)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment