Skip to content

getAttr

getAttr(element, name): string | null

Defined in: core/dom/attributes.ts:31

Returns the value of an attribute, or null if it is not set.

Pass an array of names to read several at once. The result then maps each name to its value, and attributes that are not set are left out.

Every attribute is returned as a string, including class and style. Use element.style for the style object.

Element

Element to read from.

string

Attribute name, e.g. href.

string | null

getAttr(link, 'href'); // '/docs' or null
getAttr(link, ['href', 'rel']); // { href: '/docs', rel: 'next' }

getAttr(element, names): Record<string, string>

Defined in: core/dom/attributes.ts:36

Element

Element to read from.

string[]

Attribute names, e.g. ['href', 'rel'].

Record<string, string>