The elementsFromPoint()
method of the Document
interface returns an array of all elements at the specified coordinates (relative to the viewport).
It operates in a similar way to the elementFromPoint()
method.
The elementsFromPoint()
method of the Document
interface returns an array of all elements at the specified coordinates (relative to the viewport).
It operates in a similar way to the elementFromPoint()
method.
elementsFromPoint(x, y)
x
The horizontal coordinate of a point.
y
The vertical coordinate of a point.
An array of element
objects.
<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); for (var i = 0; i < elements.length; i++) { output.textContent += elements[i].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 | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
elementsFromPoint |
43
Before Chrome 66, this method returned
null when the element was a child of a host node. See
issue 759947.
|
79
12-79
Returns a
NodeList 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
|
10
Returns a
NodeList 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).
|
30
|
11.1
|
43
Before WebView 66, this method returned
null when the element was a child of a host node. See
issue 759947.
|
43
Before Chrome 66, this method returned
null when the element was a child of a host node. See
issue 759947.
|
46
|
30
|
11.3
|
4.0
Before Samsung Internet 9.0, this method returned
null when the element was a child of a host node. See
issue 759947.
|
© 2005–2021 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