`DocumentOrShadowRoot` 接口的 `elementFromPoint()` 方法返回给定坐标点的顶端 `element` 。

If the element at the specified point belongs to another document (for example, an iframe's subdocument), the subdocument's parent element is returned (the iframe itself). If the element at the given point is anonymous or XBL generated content, such as a textbox's scroll bars, then the first non-anonymous ancestor element (for example, the textbox) is returned.

If you need to find the specific position inside the element, use `Document.caretPositionFromPoint()`.

## Syntax

`var element = document.elementFromPoint(x, y);`

x

y

## Example

```<!DOCTYPE html>
<html lang="en">
<title>elementFromPoint example</title>

<script>
function changeColor(newColor) {
elem = document.elementFromPoint(2, 2);
elem.style.color = newColor;
}
</script>

<body>
<p id="para1">Some text here</p>
<button onclick="changeColor('blue');">blue</button>
<button onclick="changeColor('red');">red</button>
</body>
</html>
```

## Specifications

Specification Status Comment