mozilla
Your Search Results

    Document.elementFromPoint()

    This is an experimental technology
    Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.

    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.

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

    Syntax

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

    Returns

    The topmost Element object under the given points.

    Parameters

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

    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.53 (Yes)
    Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
    Basic support ? (Yes) ? ? ? ?

     

    Hide Sidebar