Created
October 9, 2014 23:36
-
-
Save ToJans/332cb784e69ac852cfd3 to your computer and use it in GitHub Desktop.
mquery - a minimalistic version of jquery
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
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 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
// 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