Created
February 19, 2015 15:43
-
-
Save vectorsize/feda8ac1ebc889c33b6f to your computer and use it in GitHub Desktop.
Lazy-ass jquery ~ esque utility
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
// 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