This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
The elementsFromPoint() method of the Document interface returns an array of all elements at the specified coordinates (relative to the viewport). The elements are ordered from the topmost to the bottommost box of the viewport.
It operates in a similar way to the elementFromPoint() method.
elementsFromPoint(x, y)
An array of Element objects, ordered from the topmost to the bottommost box of the viewport.
<div> <p>Some text</p> </div> <p>Elements at point 30, 20:</p> <div id="output"></div>
let output = document.getElementById("output");
if (document.elementsFromPoint) {
let elements = document.elementsFromPoint(30, 20);
elements.forEach((elt, i) => {
output.textContent += elt.localName;
if (i < elements.length - 1) {
output.textContent += " < ";
}
});
} else {
output.innerHTML = `<span style="color: red">
Browser does not support
<code>document.elementsFromPoint()</code>
</span>
`;
}
| Specification |
|---|
| CSSOM View Module> # dom-document-elementsfrompoint> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
elementsFromPoint |
43Before Chrome 66, this method returnednull when the element was a child of a host node. See bug 40537452. |
7912–79Returns aNodeList instead of an array. See the MSDN documentation. Returns null when the point provided has no elements beneath it (e.g., when given a point outside the document). |
46 | 30 | 11.1 | 43Before Chrome Android 66, this method returnednull when the element was a child of a host node. See bug 40537452. |
46 | 30 | 11.3 | 4.0Before Samsung Internet 9.0, this method returnednull when the element was a child of a host node. See bug 40537452. |
43Before WebView Android 66, this method returnednull when the element was a child of a host node. See bug 40537452. |
11.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/Document/elementsFromPoint