Document: elementsFromPoint() method
Baseline Widely available
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.
Syntax
js
elementsFromPoint(x, y)
Parameters
Return value
An array of Element
objects, ordered from the topmost to the bottommost box of the viewport.
Examples
HTML
html
<div>
<p>Some text</p>
</div>
<p>Elements at point 30, 20:</p>
<div id="output"></div>
JavaScript
js
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>
`;
}
Specifications
Specification |
---|
CSSOM View Module # dom-document-elementsfrompoint |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
elementsFromPoint |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.
- Requires a vendor prefix or different name for use.
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.