Baseline Widely available
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.
x
The horizontal coordinate of a point.
y
The vertical coordinate of a point.
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>
JavaScript
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 Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4