MouseEvent pageX Property
Example
Get the coordinates of the mouse pointer when a mouse button is clicked:
let x = event.pageX; // Horizontal
let y = event.pageY; // Vertical
Try it Yourself »
More examples below.
Description
The pageX
property returns the document relative X coordinate of the mouse pointer when a mouse event
occurs.
The pageX
property is read-only.
The document is the web page.
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:
Syntax
event.pageX
Technical Details
Return Value: |
A Number. The X coordinate of the mouse pointer, in pixels. |
---|---|
DOM Version: | DOM Level 4 Mouse Events |
More Examples
Example
The coordinates of the mouse pointer while the mouse pointer moves:
var x = event.pageX;
var y = event.pageY;
Try it Yourself »
Example
The differences between pageX and pageY and screenX and screenY:
let pX = event.pageX;
let pY = event.pageY;
let sX = event.screenX;
let sY = event.screenY;
Try it Yourself »
Browser Support
event.pageX
is a DOM Level 4 (2015) feature.
It is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
event.pageX
is not supported in Internet Explorer 11 (or earlier).