HtmlElementLike

Metadata callbacks receive an HtmlElementLike representing the element being evaluated. It exposes a subset of the browser element API.

closest() method

Finds the element itself or its nearest matching ancestor.

Syntax

closest(selectors: string): HtmlElementLike | null | undefined

Return value

The element itself or its nearest matching ancestor, or null/undefined if none matches.

Parameters

getAttribute() method

Returns the value of the named attribute, or a nullish value if the attribute is absent. Dynamic attributes may return a DynamicValue.

Syntax

getAttribute(name: string): string | DynamicValue | null | undefined

Return value

The attribute value, a DynamicValue for dynamic attributes, or null/undefined if absent.

Parameters

hasAttribute() method

Returns whether the named attribute is present.

Syntax

hasAttribute(name: string): boolean

Return value

true if the attribute is present, otherwise false.

Parameters

matches() method

Tests whether this element matches the selector list, including selectors that describe its context (for example, section > my-component).

Syntax

matches(selectors: string): boolean

Return value

true if this element matches the selector list, otherwise false.

Parameters