added prettier and eslint for dev
This commit is contained in:
32
lib/domUtils.ts
Normal file
32
lib/domUtils.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export const addGlobalEventListener = (
|
||||
type: string,
|
||||
selector: string,
|
||||
callback: (arg0: Event) => void,
|
||||
options: boolean | AddEventListenerOptions,
|
||||
parent = document
|
||||
): void => {
|
||||
parent.addEventListener(
|
||||
type,
|
||||
(e: Event) => {
|
||||
if (e != null && e.target != null) {
|
||||
const el = e.target as Element
|
||||
if (el.matches(selector)) callback(e)
|
||||
}
|
||||
},
|
||||
options
|
||||
)
|
||||
}
|
||||
|
||||
export const qs = (
|
||||
selector: string | keyof HTMLElementTagNameMap,
|
||||
parent = document
|
||||
): Element => {
|
||||
return parent.querySelector(selector)
|
||||
}
|
||||
|
||||
export const qsa = (
|
||||
selector: string | keyof HTMLElementTagNameMap,
|
||||
parent = document
|
||||
): Element[] => {
|
||||
return [...parent.querySelectorAll(selector)]
|
||||
}
|
Reference in New Issue
Block a user