DocumentOrShadowRoot.elementsFromPoint()

This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The elementsFromPoint() property of the DocumentOrShadowRoot interface returns an array of all elements at the specified coordinates (relative to the viewport).

Syntax

var elements = document.elementsFromPoint(x, y);

Parameters

x
The horizontal coordinate of a point.
y
The vertical coordinate of a point.

Returns

An array of element objects.

Example

HTML Content

<div>
  <p>Some text</p>
</div>
<p>Elements at point 30, 20:</p>
<div id="output"></div>

JavaScript Content

var output = document.getElementById("output");
if (document.elementsFromPoint) {
  var 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>";
}

Specifications

Specification Status Comment
Shadow DOM
The definition of 'DocumentOrShadowRoot' in that specification.
Working Draft Initial definition.

Browser Compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 53.0 (Yes)[1] (Yes)[1] (Yes)[1] (Yes)[1]
Feature Android Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support (Yes)[1] 53.0 (Yes)[1] (Yes)[1] (Yes)[1] (Yes)[1] 53.0

[1] Implemented on the Document interface.

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, HolgerJeromin, mbhall88, bunnybooboo, jpmedley
 Last updated by: chrisdavidmills,