webcoreui
Version:
UI component and template library for Astro, Svelte, and React apps styled with Sass.
29 lines (22 loc) • 703 B
text/typescript
export const get = (selector: string, all?: boolean) => all
? document?.querySelectorAll(selector)
: document?.querySelector(selector)
export const on = (
selector: string | HTMLElement | Document,
event: string,
callback: any,
all?: boolean
) => {
if (all) {
const elements = document.querySelectorAll(selector as string)
elements?.forEach(element => {
element.addEventListener(event, callback)
})
return
}
if (typeof selector === 'string') {
(get(selector) as HTMLElement)?.addEventListener(event, callback)
return
}
selector?.addEventListener(event, callback)
}