Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten.Erfahre mehr über dieses Experiment.
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 Januar 2020.
DieelementsFromPoint()-Methode desDocument-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 dieelementFromPoint()-Methode.
In diesem Artikel
Syntax
js
elementsFromPoint(x, y)Parameter
Rückgabewert
Ein Array vonElement-Objekten, geordnet vom obersten bis zum untersten Kasten des Viewports.
Beispiele
>HTML
html
<div> <p>Some text</p></div><p>Elements at point 30, 20:</p><div></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> Browser does not support <code>document.elementsFromPoint()</code></span>`;}Spezifikationen
| Specification |
|---|
| CSSOM View Module> # dom-document-elementsfrompoint> |