Skip to content

Function: getElement() ​

Overload 1 ​

getElement<K>(tag): HTMLElementTagNameMap[K] | null

Defined in: dom.ts:23

Returns the first element matching the given tag name, or null if none exists.

Type Parameters ​

K ​

K extends keyof HTMLElementTagNameMap

Parameters ​

tag ​

K

The HTML tag name to search for.

Returns ​

HTMLElementTagNameMap[K] | null

Returns the found element, or null.

Example ​

ts
// HTML
<button>Click Me!</button>
// JS
const myButton = facile.getElement('button');

Overload 2 ​

getElement<T>(selector): T | null

Defined in: dom.ts:36

Returns the first element matching the given CSS selector, or null if none exists.

Type Parameters ​

T ​

T extends Element = Element

The expected element type. Uses Element by default.

Parameters ​

selector ​

string

A CSS selector string.

Returns ​

T | null

Returns the found element, or null.

Example ​

ts
// HTML
<button id="my-button">Click Me!</button>
// JS
const myButton = facile.getElement('#my-button');