Skip to content

UseQuerySelector

katanakit-js / useQuerySelector

const useQuerySelector: {
<K>(selector): HTMLElementTagNameMap[K] | null;
<E>(selector): E | null;
};

Defined in: infrastructure/dom/dom.service.ts:112

Returns the first element matching a CSS selector.

<K>(selector): HTMLElementTagNameMap[K] | null;
Type Parameter
K extends keyof HTMLElementTagNameMap
Parameter Type
selector K

HTMLElementTagNameMap[K] | null

<E>(selector): E | null;
Type Parameter Default type
E extends Element HTMLElement
Parameter Type
selector string

E | null

E

The expected Element subtype.

selector

A CSS selector string.

The matching element, or null.

const el = useQuerySelector<HTMLElement>(".my-class");