目录

MouseEvent offsetX Property

Example

Get the x coordinate of a click:

let x = event.offsetX;
Try it Yourself »

Description

The offsetX property returns the relative horizontal coordinate of the mouse pointer when a mouse event occurs.

The offsetX property is read-only.


Coordinate Properties

Property Relative to
The screenX Property The Screen area
The screenY Property The Screen area
The clientX Property The Window area
The clientY Property The Window area
The pageX Property The Page (Document)
The pageY Property The Page (Document)
The offsetX Property The target Element
The offsetY Property The target Element

See Also:

The Mouse Event Object



Syntax

event.offsetX

Technical Details

Return Value: A Number.
The X (horizontal) pixel coordinate of the mouse pointer.
DOM Version: DOM Level 4 Mouse Events.

Browser Support

event.offsetX is a DOM Level 1 (1998) feature.

It is fully supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 9-11