Add `$.on` vanilla JS substitute

This commit is contained in:
Andreas Nedbal 2021-12-25 03:31:30 +01:00
parent 89127aa313
commit 3b5e963da5
1 changed files with 7 additions and 0 deletions

View File

@ -0,0 +1,7 @@
export function on(type: string, selector: string, callback: Function): void {
document.addEventListener(type, (event: Event) => {
if ((event.target as HTMLElement).matches(selector)) {
callback(event);
}
});
};