Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.
The elementFromPoint() method, available on the ShadowRoot object, returns the element at the topmost shadow root layer at the specified coordinates relative to the viewport (the shadow root highest in the display z-order, that is able to receive pointer events). Shadow root elements that have pointer-events set to none are ignored.
If the specified point is outside the bounds of the shadow root, the result is undefined.
elementFromPoint(x, y)
xThe horizontal coordinate of a point, relative to the left edge of the current viewport.
yThe vertical coordinate of a point, relative to the top edge of the current viewport.
An Element; the topmost shadow root element located at the specified coordinates, if any.
In this example, assuming the existence of a <template> in the HTML, we define a <my-custom-element>. If the appended custom element abuts the top-left corner of the viewport, or any portion of it overlaps that corner, the element that is the topmost layer at that point in the custom element will have a thin, dashed red border.
customElements.define(
"my-custom-element",
class extends HTMLElement {
constructor() {
super();
const templateContent = document.getElementById(
"my-custom-element-template",
).content;
const sRoot = this.attachShadow({ mode: "open" });
sRoot.appendChild(templateContent.cloneNode(true));
// get the topmost element in the top left corner of the viewport
const srElement = this.shadowRoot.elementFromPoint(0, 0);
// apply a border to that element
srElement.style.border = "1px dashed red";
}
},
);
Not part of any standard.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
elementFromPoint |
53Before Chrome 66, this method returnednull when the element was a child of a host node. See bug 40537452. |
79 | 63 | 40Before Opera 53, this method returnednull when the element was a child of a host node. See bug 40537452. |
10.1 | 53Before Chrome Android 66, this method returnednull when the element was a child of a host node. See bug 40537452. |
63 | 41Before Opera Android 47, this method returnednull when the element was a child of a host node. See bug 40537452. |
10.3 | 6.0Before Samsung Internet 9.0, this method returnednull when the element was a child of a host node. See bug 40537452. |
53Before WebView Android 66, this method returnednull when the element was a child of a host node. See bug 40537452. |
10.3 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot/elementFromPoint