Document: elementsFromPoint()-Methode
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.
Die elementsFromPoint()
-Methode des Document
-Interfaces gibt ein Array von allen Elementen an den angegebenen Koordinaten (relativ zum Viewport) zurück. Die Elemente sind vom obersten bis zum untersten Kasten des Viewports geordnet.
Sie funktioniert in ähnlicher Weise wie die elementFromPoint()
-Methode.
Syntax
elementsFromPoint(x, y)
Parameter
Rückgabewert
Ein Array von Element
-Objekten, geordnet vom obersten bis zum untersten Kasten des Viewports.
Beispiele
HTML
<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>
`;
}
Spezifikationen
Specification |
---|
CSSOM View Module # dom-document-elementsfrompoint |
Browser-Kompatibilität
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.