added more functions

This commit is contained in:
2022-03-31 05:33:59 +02:00
parent 110e83afdf
commit 23957950df
6 changed files with 98 additions and 53 deletions

24
src/domUtils.ts Normal file
View File

@@ -0,0 +1,24 @@
export function addGlobalEventListener(
type: string,
selector: string,
callback: (arg0: Event) => void,
options: boolean | AddEventListenerOptions,
parent = document
): void {
parent.addEventListener(
type,
e => {
// @ts-ignore
if (e.target.matches(selector)) callback(e)
},
options
)
}
export function qs(selector: string, parent = document): Element {
return parent.querySelector(selector)
}
export function qsa(selector: string, parent = document): Element[] {
return [...parent.querySelectorAll(selector)]
}