Sign up (with export icon)

utils/dom/getelementfrompoint

Api-module iconmodule

Functions

  • Chevron-right icon

    getElementFromPoint( x, y, shadowRoots ) → Element | null

    Returns the topmost element at the given viewport point, looking inside the given shadow roots.

    The shadow-aware replacement for Document#elementFromPoint(), which retargets a point inside a shadow tree to that tree's host and so cannot report the element actually under it.

    Pass every shadow root a hit may land in – typically each editable's own getRootNode(). Only the innermost root containing the point matters, so ancestor roots do not need to be listed, and a point in the light DOM needs no roots at all.

    The point is hit tested strictly, honoring pointer-events, so the answer is the element that a click at those coordinates would reach. The exception is an engine that cannot hit test a shadow root, where the point is resolved from the nearest caret position instead and may land beside what it really hit.

    Parameters

    x: number

    The horizontal coordinate, relative to the viewport.

    y: number

    The vertical coordinate, relative to the viewport.

    shadowRoots: Array<ShadowRoot>

    The shadow roots the lookup is allowed to look inside. Empty for the light DOM.

    Defaults to []

    Returns

    Element | null