elementFromPoint
Summary
Returns the element at the specified x and y coordinates.
Method of dom/Documentdom/Document
Syntax
var element = document.elementFromPoint(x, y);
Parameters
x
- Data-type
- double
A number that specifies the X-offset, in pixels. Zero-based.
y
- Data-type
- double
A number that specifies the Y-offset, in pixels. Zero-based.
Return Value
Returns an object of type DOM NodeDOM Node
The element at the given point.
Examples
Listen for click event on entire document, log nodeName of element found with elementFromPoint()
document.addEventListener("click", function(event){
var el = document.elementFromPoint(event.clientX, event.clientY);
console.log(el.nodeName);
});
Usage
This methods is used to get the element from the document whose elementFromPoint method is being called which is the topmost element which lies under the given point. To get an element, specify the point via coordinates, in CSS pixels, relative to the upper-left-most point in the window or frame containing the document.
Notes
Coordinates are supplied in client coordinates. The upper-left corner of the client area is (0,0). For elementFromPoint to exhibit expected behavior, the object or element located at position (x, y) must support and respond to mouse events.
Related specifications
- CSSOM View Module
- Editor’s Draft 3
See also
Related pages
Attributions
Mozilla Developer Network : Article
Microsoft Developer Network: [Windows Internet Explorer API reference Article]