Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 함께 해서 번역을 마치도록 도와 주세요!

The elementFromPoint() method of the Document interface returns the topmost element at the specified coordinates.

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 the specified point is outside the visible bounds of the document or either coordinate is negative, the result is null.

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

Note: Callers from XUL documents should wait until the onload event has fired before calling this method.

Syntax

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

Parameters

x
A horizontal position within the current viewport.
y
A vertical position within the current viewport.

Return value

The topmost Element object under the given points.

Example

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

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

<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
CSS Object Model (CSSOM) View Module
The definition of 'elementFromPoint' in that specification.
Working Draft Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support  4.0 3 5.5 10.50 (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? (Yes) ? ? ? ?

문서 태그 및 공헌자

 최종 변경: Sebastianz,