added more functions
This commit is contained in:
24
src/domUtils.ts
Normal file
24
src/domUtils.ts
Normal 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)]
|
||||
}
|
Reference in New Issue
Block a user