Skip to content

Instantly share code, notes, and snippets.

@ToJans
Created October 9, 2014 23:36
Show Gist options
  • Save ToJans/332cb784e69ac852cfd3 to your computer and use it in GitHub Desktop.
Save ToJans/332cb784e69ac852cfd3 to your computer and use it in GitHub Desktop.
mquery - a minimalistic version of jquery
function $(selector) {
if (typeof (selector) == "function") {
document.addEventListener('DOMContentLoaded', selector)
} else {
return [].reduce.call(document.querySelectorAll(selector), function (acc, element) {
return acc.concat([element]);
}, [])
}
}
// this function will be called when the document is loaded.
$(function () {
// an example
$("input.someclass").forEach(function (input) {
input.addEventListener("click", function(e){
console.log(e);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment