Files
mal/static/q.ts
2026-06-25 02:35:52 +02:00

11 lines
508 B
TypeScript

/** QuerySelector on a container element, scoped to that element. */
export const q = <T extends Element>(container: HTMLElement, selector: string): T | null =>
container.querySelector(selector);
/** QuerySelector on the document. */
export const qs = <T extends Element>(selector: string): T | null =>
document.querySelector(selector);
/** Get a data attribute value from an element, defaults to empty string. */
export const dataset = (el: HTMLElement, key: string): string => el.dataset[key] ?? "";