Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vectorsize
Created February 19, 2015 15:43
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 vectorsize/feda8ac1ebc889c33b6f to your computer and use it in GitHub Desktop.
Save vectorsize/feda8ac1ebc889c33b6f to your computer and use it in GitHub Desktop.
Lazy-ass jquery ~ esque utility
// adds shorcuts
var addShorcuts = function(el) {
el.on = el.addEventListener;
el.off = el.removeEventListener;
return el;
};
module.exports = function Lquery(sel) {
// get a proper array of the results
let els = [].slice.call(document.querySelectorAll(sel));
if(els.length == 1) {
els = addShorcuts(els[0]);
} else {
els.map(addShorcuts);
// add each to forEach shortcut
els.each = els.forEach;
}
// return array or item
return els;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment