closest

The closest JS Element returns the first (starting at element) inclusive ancestor that matches selectors, and null otherwise.

Syntax

element.closest(selectors)

Parameters

selectors

Patterns that match elements in a tree structure.

Examples

1 · null

2 · ancestor

matches

attachShadow

classList

className

getAttribute

getAttributeNames

getAttributeNS

hasAttribute

hasAttributeNS

hasAttributes

id

innerHTML

insertAdjacentHTML

localName

matches

namespaceURI

outerHTML

prefix

removeAttribute

removeAttributeNS

setAttribute

setAttributeNS

shadowRoot

slot

tagName

toggleAttribute

Web Hypertext Application Technology Working Group (WHATWG)

Home Menu