Sign up (with export icon)

utils/dom/containsnode

Api-module iconmodule

Functions

  • Chevron-right icon

    containsNode( container, node ) → boolean

    Checks whether node is inside container, looking through shadow roots on the way.

    Use it instead of Node#contains(), which stops at a shadow root: that one says false even when container really is an ancestor, as long as a shadow root sits between the two. A node contains itself here, just like it does there.

    container can also be a Document or a ShadowRoot – useful for a scroll event, for example, whose target is the document and not an element. Works with open and closed shadow roots.

    Parameters

    container: Node

    The node that may be the ancestor.

    node: Node | null

    The node to look for. May be null, which always gives false.

    Returns

    boolean