jQuery event.pageX Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Events

Definition

event.pageX is a Number on the jQuery event object. It is the mouse pointer’s horizontal position in pixels relative to the left edge of the document (scroll included). Added in jQuery 1.0.4. Pair it with event.pageY for a full document (x, y) point.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
event.pageX   // Number — px from document left (read-only)

$(document).on("mousemove", function (event) {
  // pageX: horizontal · pageY: vertical
  console.log(event.pageX, event.pageY);
});

pageX  → document coordinates (includes scroll)
clientX → viewport coordinates (visible window)
offsetX → relative to the event target element
CallWhat it does
event.pageXLearn jQuery event.pageX: horizontal mouse position relative to the document left edge, official mousemove demo with pageY, pageX vs clientX, click coordinates, examples, pitfalls, and FAQs.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Choose a mouse event (mousemove, click, mousedown, …).
Step 2Bind with .on("mousemove", handler) (or click / mousedown).
Step 3Inside the handler, read event.pageX — pixels from the document’s left edge.

Return Value

Return ValueDescription
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

Example 1 — Official Demo: Log pageX / pageY

On mousemove, show both document coordinates (official idea).

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

How It Works

  1. Bind. mousemove on document catches moves anywhere on the page.
  2. Read X. event.pageX is distance from the document’s left edge.
  3. Read Y. event.pageY is distance from the document’s top edge.

Example 2 — Click Coordinates

Capture where the user clicked using pageX and pageY.

jQuery
$(document).on("click", function (event) {
  $("#out").text(
    "Clicked at pageX: " + event.pageX +
    ", pageY: " + event.pageY
  );
});
Try It Yourself

How It Works

  1. Bind click. One handler for any click on the page.
  2. Read. pageX / pageY are the click point in document space.
  3. Show. Write the pair into #out.

Example 3 — pageX vs clientX

Document coordinates include scroll; viewport coordinates do not.

jQuery
$(document).on("click", function (event) {
  $("#out").text(
    "pageX: " + event.pageX + " (document)\n" +
    "clientX: " + event.clientX + " (viewport)\n" +
    "scrollX: " + window.scrollX
  );
});
Try It Yourself

How It Works

  1. pageX. Measured from the document’s left edge.
  2. clientX. Measured from the viewport’s left edge.
  3. Scroll. When scrollX > 0, pageX is larger than clientX.

Frequently Asked Questions

event.pageX is a Number on the jQuery event object. It is the mouse pointer’s horizontal position in pixels relative to the left edge of the document — including any horizontal scroll. 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 document scroll — roughly pageX ≈ clientX + window.scrollX. Use pageX for document-wide coordinates; clientX for viewport-fixed UI.
pageX is horizontal (from the document’s left edge). pageY is vertical (from the document’s top edge). Together they form a (x, y) point in document space — the official jQuery demo logs both on mousemove.
Mouse events expose pageX — mousemove, mouseenter, mouseleave, mouseover, mouseout, mousedown, mouseup, and click. Keyboard events do not carry a meaningful pointer pageX.
No. pageX is read-only — the browser sets it from the pointer when the event fires. Read pageX and apply it to your own variables or element positions.
pageX is relative to the entire document. offsetX is relative to the event target’s padding edge. Use pageX for absolute document positioning; offsetX for clicks inside a specific box.

Next: event.pageY Property

Read the vertical document coordinate and complete the (x, y) pair.

event.pageY Property tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

9 people found this page helpful