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

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

See Also:

The Mouse Event Object



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).



Copyright 1999-2023 by Refsnes Data. All Rights Reserved.