Windows apps
Collapse the table of content
Expand the table of content

offsetX property

Sets or retrieves the x-coordinate of a pointer's position relative to the object firing the event.



p = object.offsetX

Property values

Type: Integer

the x-coordinate, in pixels.


The property is read/write.

The coordinates match the offsetLeft and offsetTop properties of the object. Use offsetParent to find the container object that defines this coordinate system.


This example uses the offsetX property to determine the mouse position relative to the container that fired the event, and displays the mouse coordinates in the status bar at the bottom of the window.

function offsetCoords()
    var offsetInfo = ""
    offsetInfo = "The x coordinate is: " + window.event.offsetX + "\r"
    offsetInfo += "The y coordinate is: " + window.event.offsetY + "\r"
<BODY onmousemove="window.status = 'X=' + window.event.offsetX + 
    ' Y=' + window.event.offsetY" ondblclick="offsetCoords()">
<DIV onclick="offsetCoords();" . . . position:absolute; top:200;



Send comments about this topic to Microsoft

Build date: 11/26/2012

© 2016 Microsoft