jQuery event.pageX

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Event object · jQuery 1.0.4+

What You’ll Learn

event.pageX is a Number property with the pointer’s horizontal position relative to the document’s left edge — scroll included. This tutorial covers the official mousemove demo, pairing with pageY, comparing with clientX, click pins, and drag tracking.

01

Property

event.pageX

02

Returns

Number (px)

03

Official

mousemove log

04

Document

Left edge

05

pageY

Vertical pair

06

Since 1.0.4

Mouse events

Introduction

When the user moves or clicks the mouse, you often need to know where the pointer was. jQuery forwards coordinate properties from the browser on its event object — including event.pageX for horizontal document position.

Unlike viewport coordinates (clientX), pageX counts pixels from the left edge of the full document, so it stays consistent when the page is scrolled vertically or horizontally. jQuery has exposed it since version 1.0.4.

Understanding event.pageX

This property answers one question: how far right is the pointer from the document’s left edge?

  • Origin — left edge of the document (not the viewport, not the clicked element).
  • Includes scroll — horizontal scroll offset is included in the value.
  • Read-only — a Number in pixels; not a method.
  • Pair with pageY — use both for full document coordinates.
💡
Beginner Tip

Think of the document as a large canvas. pageX is how many pixels from the canvas left border the mouse sits — even if you scrolled the window to see a different part of that canvas.

📝 Syntax

Official jQuery API form (since 1.0.4):

jQuery
event.pageX

// typical pattern:
$( document ).on( "mousemove", function ( event ) {
  console.log( "X:", event.pageX, "Y:", event.pageY );
});

Parameters

  • NonepageX is a property, not a function.

Return value

  • Number — horizontal mouse position in pixels relative to the left edge of the document.

Official jQuery API example

jQuery
$( document ).on( "mousemove", function ( event ) {
  $( "#log" ).text( "pageX: " + event.pageX + ", pageY: " + event.pageY );
});

⚡ Quick Reference

PropertyRelative toAxis
event.pageXDocument left edgeHorizontal
event.pageYDocument top edgeVertical
event.clientXViewport left edgeHorizontal
event.clientYViewport top edgeVertical
event.offsetXTarget elementHorizontal (local)

📋 pageX vs clientX vs offsetX

Three horizontal coordinates — same click, different reference frames.

pageX
event.pageX

Document — scroll included

clientX
event.clientX

Viewport — visible window

offsetX
event.offsetX

Event target element

pageY
event.pageY

Vertical document coordinate

Examples Gallery

Example 1 follows the official jQuery mousemove demo. Examples 2–5 cover click pins, scroll comparison, drag tracking, and coordinate readouts.

📚 Official jQuery Demo

Log pageX and pageY on every mousemove.

Example 1 — Official Demo: mousemove coordinates

Official jQuery demo — update a log with document X and Y on mousemove.

jQuery
$( document ).on( "mousemove", function ( event ) {
  $( "#log" ).text( "pageX: " + event.pageX + ", pageY: " + event.pageY );
});
Try It Yourself

How It Works

Each mousemove dispatch includes fresh pageX / pageY values from the browser. jQuery passes them through unchanged on its event object.

Example 2 — Click pin: place marker at pageX, pageY

On canvas click, position an absolute marker using document coordinates.

jQuery
$( "#canvas" ).on( "click", function ( event ) {
  $( "#pin" ).css({
    left: event.pageX + "px",
    top: event.pageY + "px"
  });
  $( "#coords" ).text( "Pinned at pageX: " + event.pageX );
});
Try It Yourself

How It Works

Absolutely positioned elements use document coordinates when position: absolute relative to the document body — pageX maps directly to left.

📈 Practical Patterns

Scroll comparison, drag, and HUD readouts.

Example 3 — Scrolled page: pageX vs clientX

Log both coordinates — after scrolling, pageX and clientX diverge horizontally when the page has horizontal scroll (or use vertical scroll to see pageY vs clientY).

jQuery
$( document ).on( "click", function ( event ) {
  $( "#compare" ).html(
    "pageX: " + event.pageX + " (document)
" + "clientX: " + event.clientX + " (viewport)" ); });
Try It Yourself

How It Works

pageX adds scroll offsets — roughly clientX + document scrollLeft. Pick page coordinates for document-absolute placement.

Example 4 — Drag: track delta with pageX

Store start pageX on mousedown; update position using difference on mousemove.

jQuery
var startX, startLeft;

$( "#box" ).on( "mousedown", function ( event ) {
  startX = event.pageX;
  startLeft = parseInt( $( this ).css( "left" ), 10 ) || 0;
  $( document ).on( "mousemove.drag", onDrag );
});

function onDrag( event ) {
  $( "#box" ).css( "left", startLeft + ( event.pageX - startX ) );
}
Try It Yourself

How It Works

Deltas from pageX are scroll-stable — the difference between two pageX readings equals pointer movement in document space.

Example 5 — HUD: pageX under cursor on hover

Show a floating readout with horizontal document coordinate over a chart area.

jQuery
$( "#chart" ).on( "mousemove", function ( event ) {
  $( "#hud" )
    .text( "pageX: " + Math.round( event.pageX ) )
    .css({ left: event.pageX + 12, top: event.pageY + 12 })
    .show();
});

$( "#chart" ).on( "mouseleave", function () {
  $( "#hud" ).hide();
});
Try It Yourself

How It Works

Charts and maps often map pageX (adjusted by element offset) to data values — the HUD demonstrates live horizontal document position.

🚀 Common Use Cases

  • Coordinate display — show pointer X/Y in debugging HUDs.
  • Image annotation — place pins at click pageX / pageY.
  • Drag and drop — compute movement deltas with page coordinates.
  • Drawing apps — line tools using document-space points.
  • Heatmaps — log click positions for analytics.
  • Custom sliders — map horizontal pageX to value ranges.

🧠 How pageX Works

1

Pointer event

User moves or clicks — browser fires mousemove, click, etc.

Event
2

Browser computes

Native event gets pageX from viewport position plus scroll offsets.

Native
3

jQuery handler

Your .on() callback reads event.pageX as a Number.

Read
4

Position UI

Place markers, drag elements, or map X to data — scroll-aware document space.

📝 Notes

  • Available since jQuery 1.0.4 — returns a Number (pixels).
  • Read-only property on mouse events.
  • Relative to the document left edge, not the clicked element.
  • Always pair with pageY for 2D document coordinates.
  • Use clientX for fixed viewport overlays; offsetX for local element coords.
  • jQuery normalizes coordinates consistently across supported browsers.

Browser Support

event.pageX is forwarded on jQuery’s event object since jQuery 1.0.4+ for mouse events. Underlying values come from the DOM MouseEvent pageX property — supported in all browsers jQuery targets.

jQuery 1.0.4+ · all browsers

jQuery event.pageX

Horizontal pointer position in document space.

100% Universal
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
pageX Number (px)

Bottom line: Read event.pageX on mousemove or click — document left edge origin.

Conclusion

event.pageX gives the pointer’s horizontal distance from the document’s left edge — the official demo logs it alongside pageY on mousemove.

Use it for scroll-stable positioning, drag deltas, and click annotations — and choose clientX or offsetX when your reference frame is the viewport or a single element.

💡 Best Practices

✅ Do

  • Use pageX + pageY for document-absolute placement
  • Compute drag deltas with differences of pageX readings
  • Round for display: Math.round(event.pageX)
  • Subtract element offset when mapping to local chart data
  • Prefer page coords when the page may scroll during interaction

❌ Don’t

  • Call event.pageX() with parentheses
  • Confuse pageX with clientX after scrolling
  • Use pageX on keyboard-only events for pointer position
  • Assume pageX is relative to the clicked child — use offsetX
  • Assign to event.pageX — it is read-only

Key Takeaways

Knowledge Unlocked

Five things to remember about pageX

Document horizontal mouse coordinate.

5
Core concepts
doc 02

Document

Left edge

Origin
demo 03

Official

mousemove

Demo
Y 04

pageY

Vertical pair

Pair
vs 05

clientX

Viewport

Compare

❓ Frequently Asked Questions

event.pageX is a Number property on the jQuery event object. It returns the mouse pointer's horizontal coordinate relative to the left edge of the document — including scrolled content. Available since jQuery 1.0.4 on mouse events such as mousemove, click, and mousedown.
clientX is relative to the browser viewport (visible window). pageX includes horizontal scroll offset — pageX equals clientX plus the document's horizontal scroll. Use pageX when you need document-wide coordinates; clientX for viewport-fixed UI like tooltips.
pageX is horizontal (distance from the document's left edge). pageY is vertical (distance from the document's top edge). Together they give a full (x, y) point in document space — the official jQuery demo logs both on mousemove.
Mouse events expose pageX — including mousemove, mouseenter, mouseleave, mouseover, mouseout, mousedown, mouseup, and click. Keyboard events do not have meaningful pageX values for pointer position.
No. pageX is read-only — the browser sets it from the pointer position when the event fires. To move UI, read pageX and apply the value to your own variables or CSS.
pageX is relative to the entire document. offsetX is relative to the event target element's padding edge. Use pageX for absolute document positioning (pins on a map); offsetX for clicks inside a specific box.
Did you know?

Before unified pointer events, cross-browser mouse coordinates were painful — jQuery has forwarded pageX and pageY since 1.0.4 so plugins could rely on one document-space API. The names mirror the DOM MouseEvent properties exactly.

Next: event.pageY

Read vertical document coordinates — the pair to pageX.

event.pageY tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful