THE WORLD'S LARGEST WEB DEVELOPER SITE

MouseEvent offsetX Property

❮ DOM Events ❮ MouseEvent

Example

Click inside a DIV and output the coordinates of the click, relative to the DIV element:

var x = event.offsetX;
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

The offsetX property returns the x-coordinate of the mouse pointer, relative to the target element.

Tip: To get the y-coordinate, use the offsetY property.

Note: This property is read-only.


Browser Support

Property
offsetX Yes 6 39 Yes Yes


Syntax

event.offsetX

Technical Details

Return Value: A Number, representing the horizontal coordinate of the mouse pointer, in pixels

Related Pages

MouseEvent: offsetY Property

MouseEvent: clientX Property

MouseEvent: clientY Property

MouseEvent: screenX Property

MouseEvent: screenY Property


❮ DOM Events ❮ MouseEvent