Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Document
  4. elementsFromPoint()

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.

TheelementsFromPoint() methodof theDocument interface returns an array of all elementsat 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 theelementFromPoint() 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 ofElement 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></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>`;}

Specifications

Specification
CSSOM View Module
# dom-document-elementsfrompoint

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp