this is a working code, but I want to simplify - correct, improve the code
window.addEvent = function(elem,type,callback) {
var evt = function(e) {
e = e || window.event;
return callback.call(elem,e);
};
var cb = function(e) { return evt(e); };
elem.addEventListener(type,cb,false);
return elem;
};
window.findParent = function(child,filter,root) {
do {
if( filter(child)) return child;
if( root && child == root) return false;
} while(child = child.parentNode);
return false;
};
function on(type, target, callback) {
window.addEvent(document.body, type, function(e) {
var s = window.findParent(e.srcElement || e.target, function(elm) {
return elm.classList.contains(target);
},this);
if( s && callback ) {
callback(e)
}
});
}
on("click", "page-link", function(e){
console.log("hey its working");
});
In this example, I update the pagination with fetch, and I have to bind addEventlistener to every page link. I am thinking about, If its there a way to resolve this with primise, or another cleaner way, using the latest techniques? (with pure Javascript)