The mousemove event fires when the pointer moves inside an element (since jQuery 1.7 with .on()). Use it for drag UI, drawing, sliders, and live coordinates. jQuery normalizes event.pageX and event.pageY across browsers.
Remember
$("#box").on("mousemove", function (event) { … })
event.pageX / pageY → document coordinates
event.clientX / clientY → viewport coordinates
.trigger("mousemove") → run handlers (coords may be undefined)
.off("mousemove") → unbind when done
Bind a light handler, read coordinates, and unbind when tracking is finished.
Select the element that should report pointer movement.
Bind with .on("mousemove", handler) (or only during drag — see below).
Read event.pageX / event.pageY (or client coords) inside the handler.
Unbind with .off("mousemove") as soon as you no longer need updates.
Piece
Required?
Role
Element
Yes
Receives movement while pointer is inside
handler
Yes
function(event) { … }
eventData
Optional
Object passed as event.data
Return
—
jQuery object (chainable)
Pseudocode
Pseudocode
on mousemove inside element:
x = event.pageX // document X
y = event.pageY // document Y
update UI lightly (or skip most frames)
// Official drag pattern (recommended):
on mousedown:
bind mousemove on document
on mouseup (document):
unbind mousemove
Reference
Cheat Sheet
Keep these facts handy while tracking the pointer.
Topic
Detail
Bind
.on("mousemove", handler) (1.7+)
Trigger
.trigger("mousemove") (1.0+)
pageX / pageY
Document origin — normalized by jQuery
clientX / clientY
Viewport origin
Frequency
Can fire hundreds of times per second
vs mouseenter
enter once; mousemove = continuous
Shorthand
.mousemove() deprecated — use .on()
Try it
Live Preview
Move the pointer over the track pad to see pageX / pageY vs clientX / clientY.
Move here
Browser demo of mousemove — same idea as the examples below.
Result
Move the pointer over the track pad
→ pageX / pageY and clientX / clientY update live
Code
jQuery Examples
Short, copy-ready snippets. Open each Try It Yourself lab for a live editor.
Example 1 — Log pageX / pageY
Append coordinates each time the pointer moves over the target — the official .on("mousemove") pattern.
jQuery
$("#target").on("mousemove", function (event) {
var msg = "Handler for mousemove called at ";
msg += event.pageX + ", " + event.pageY;
$("#log").append(msg + "\n");
});
Start on press.mousedown begins the drag and attaches mousemove to document.
Track globally. Document-level move keeps following even outside the box.
Stop on release..one("mouseup") unbinds move — works even if release is outside.
Named handler. Passing onMove to .off() removes only that listener.
Example 5 — Local Coordinates Inside a Zone
Convert document coordinates to positions relative to the element with .offset().
jQuery
var $zone = $("#zone");
$zone.on("mousemove", function (event) {
var offset = $zone.offset();
var x = event.pageX - offset.left;
var y = event.pageY - offset.top;
$("#readout").text("Local: " + Math.round(x) + ", " + Math.round(y));
});
$zone.on("mouseleave", function () {
$("#readout").text("Move inside the zone");
});
Get zone origin..offset() returns the element’s document position.
Subtract.pageX - left and pageY - top give local X/Y.
Show the readout. Round values for a clean display.
Reset on leave. Pair with mouseleave when the pointer exits.
Edge Cases & Pitfalls
Check these before shipping pointer-tracking UI.
perf
Handlers fire constantly
Hundreds of calls per second. Avoid heavy DOM work, animations, or AJAX inside every move.
unbind
Leave listeners hanging
A permanent documentmousemove wastes CPU. Unbind on mouseup (or when the feature ends).
trigger
Triggered coords may be undefined
.trigger("mousemove") is not a real pointer event. Guard or pass coordinates when needed.
mouseup
Release outside the element
Bind mouseup on document so drag cleanup still runs when the user releases elsewhere.
touch
Not a touch event
mousemove is mouse-oriented. For fingers, look at touch / pointer events separately.
Compatibility
Browser Support
The mousemove event is a standard DOM mouse event. jQuery’s .on("mousemove") (since 1.7) and normalized pageX/pageY work in any browser where your jQuery build runs.
✓ jQuery 1.7+ · Browsers
jQuery mousemove event
Supported wherever jQuery runs — Chrome, Firefox, Safari, Edge, and legacy environments with a matching jQuery build.
100%With jQuery loaded
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
mousemoveBrowsers
Bottom line: Safe in all common browsers with jQuery loaded. Prefer .on() / .off() over the deprecated .mousemove() shorthand.
Analysis
Performance Notes
Approach
Cost
Best for
Always-on mousemove
Very high frequency
Small readouts only
Bind during drag only
Active while pressed
Drag, draw, resize
Throttle / rAF
~1 update per frame
Smooth visual tracking
Official guidance: optimize handlers and unbind when finished. Prefer the mousedown → mousemove → mouseup sequence for drag UI instead of a permanent document listener.
Remember
Key Takeaways
Role: continuous pointer tracking inside an element.
Coords: prefer pageX / pageY for document-relative position.
API: use .on("mousemove"), not the deprecated .mousemove() shorthand.
Drag: bind on mousedown, unbind on document mouseup.
One line:mousemove follows the pointer — keep the handler light and unbind when you are done.
Frequently Asked Questions
mousemove fires whenever the mouse pointer moves inside an element — even by one pixel. Bind with .on('mousemove', handler) (since jQuery 1.7). Any HTML element can receive it. It is one of the highest-frequency browser events, so keep handlers light.
pageX and pageY are relative to the document (including scroll). clientX and clientY are relative to the viewport. jQuery normalizes pageX and pageY across browsers — prefer them when positioning elements on the page.
It can fire hundreds of times per second. Heavy DOM work, layout thrashing, or multiple handlers per move can slow the page. Keep handlers fast, throttle or use requestAnimationFrame when needed, and unbind as soon as tracking is done.
Bind mousemove inside a mousedown handler, then unbind on mouseup. Attach mouseup high in the DOM (often $(document).one('mouseup', fn)) because release may happen outside the original element.
Call .trigger('mousemove') on the element. Handlers run, but pageX and pageY are often undefined unless you pass a custom event object with coordinates.
Use .on('mousemove', handler). The .mousemove() shorthand is deprecated since jQuery 3.3. Unbind with .off('mousemove'). .on() also supports delegation: .on('mousemove', '.handle', fn).