MouseEvent offsetX attribute

Definition and usage

The offsetX attribute returns the x coordinate of the mouse pointer relative to the target element.

Tip:To get the y coordinate, please use the offsetY attribute.

Note:This property is read-only.

Example

Click inside the DIV and output the x coordinate of this click relative to the DIV element:

var x = event.offsetX;

Try it yourself

You can find more TIY examples below the page.

Syntax

event.offsetX

Technical details

Return value: A numerical value representing the horizontal coordinate of the mouse pointer, measured in pixels.

browser support

attribute Chrome IE Firefox Safari Opera
offsetX supported 6 39 supported supported

related pages

MouseEvent: offsetY attribute

MouseEvent: clientX attribute

MouseEvent: clientY Property

MouseEvent: screenX Property

MouseEvent: screenY Property