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

x

The horizontal coordinate of a point.

y

The vertical coordinate of a point.

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

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
elementsFromPoint
Chrome – Full support
Chrome 43 (Release date: 2015-05-19)
footnote
footnote Before Chrome 66, this method returned null when the element was a child of a host node. See bug 40537452.
Edge – No support
Edge 12 – 18 (Release date: 2015-07-29)
prefix
prefix Implemented with the vendor prefix: ms
footnote 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).
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 46 (Release date: 2016-04-26)
footnote Full support
Opera – Full support
Opera 30 (Release date: 2015-06-09)
footnote Full support
Safari – Full support
Safari 11.1 (Release date: 2018-04-12)
footnote Full support
Chrome Android – Full support
Chrome Android 43 (Release date: 2015-05-27)
footnote
footnote Before Chrome Android 66, this method returned null when the element was a child of a host node. See bug 40537452.
Firefox for Android – Full support
Firefox for Android 46 (Release date: 2016-04-26)
footnote Full support
Opera Android – Full support
Opera Android 30 (Release date: 2015-06-10)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11.3 (Release date: 2018-03-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 4 (Release date: 2016-03-11)
footnote
footnote Before Samsung Internet 9.0, this method returned null when the element was a child of a host node. See bug 40537452.
WebView Android – Full support
WebView Android 43 (Release date: 2015-05-27)
footnote
footnote Before WebView Android 66, this method returned null when the element was a child of a host node. See bug 40537452.
WebView on iOS – Full support
WebView on iOS 11.3 (Release date: 2018-03-29)
footnote Full support

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.

See also