Function closest

  • Returns the first (starting at element) inclusive ancestor that matches selectors, and null otherwise.

    Throws a "SyntaxError" if the selector is invalid.

    Type Parameters

    • K extends keyof HTMLElementTagNameMap

    Parameters

    • el: null | EventTarget
    • selector: K

    Returns null | HTMLElementTagNameMap[K]

  • Returns the first (starting at element) inclusive ancestor that matches selectors, and null otherwise.

    Throws a "SyntaxError" if the selector is invalid.

    Type Parameters

    • K extends keyof SVGElementTagNameMap

    Parameters

    • el: null | EventTarget
    • selector: K

    Returns null | SVGElementTagNameMap[K]

  • Returns the first (starting at element) inclusive ancestor that matches selectors, and null otherwise.

    Throws a "SyntaxError" if the selector is invalid.

    Type Parameters

    • E extends Element = Element

    Parameters

    • el: null | EventTarget
    • selector: string

    Returns null | E