feature: $.on(sel, ev, fn) for persistent events

This commit is contained in:
AJ ONeal 2021-07-27 17:08:55 -06:00
parent 6e6341d9ad
commit a64fd3f93c
1 changed files with 9 additions and 0 deletions

View File

@ -5,3 +5,12 @@ function $(sel, el) {
function $$(sel, el) {
return (el || document).querySelectorAll(sel);
}
$.on = function (sel, event, fn) {
document.body.addEventListener(function (ev) {
if (!ev.target.matchSelector(sel)) {
return true;
}
fn.call(ev.target, ev);
});
};