getAttr
Call Signature
Section titled “Call Signature”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.
Parameters
Section titled “Parameters”element
Section titled “element”Element
Element to read from.
string
Attribute name, e.g. href.
Returns
Section titled “Returns”string | null
Example
Section titled “Example”getAttr(link, 'href'); // '/docs' or nullgetAttr(link, ['href', 'rel']); // { href: '/docs', rel: 'next' }Call Signature
Section titled “Call Signature”getAttr(
element,names):Record<string,string>
Defined in: core/dom/attributes.ts:36
Parameters
Section titled “Parameters”element
Section titled “element”Element
Element to read from.
string[]
Attribute names, e.g. ['href', 'rel'].
Returns
Section titled “Returns”Record<string, string>