The .mousemove() method is jQuery’s legacy shorthand for binding and triggering the mousemove event. This tutorial covers .mousemove(handler) since 1.0, .mousemove(eventData, handler) since 1.4.3, no-argument .mousemove() as a trigger, migration to .on("mousemove") and .trigger("mousemove"), and why the binding form is deprecated since jQuery 3.3. For the modern mousemove event API, see the jQuery mousemove event tutorial.
01
.mousemove(fn)
Bind handler
02
eventData
Since 1.4.3
03
.mousemove()
Trigger event
04
.on()
Modern bind
05
.trigger()
Modern fire
06
Deprecated
Since 3.3
Fundamentals
Introduction
Before jQuery 1.7 unified events with .on() and .off(), every common event had a matching shorthand — .click(), .mousemove(), .keydown(), and dozens more. The .mousemove() method let you track pointer movement in one short call: $("#canvas").mousemove(function(e){ ... }). It remains in jQuery 3.x for backward compatibility but is marked deprecated.
Understanding .mousemove() matters when reading older drag-and-drop plugins, drawing tools, and legacy tutorials. The method does two distinct jobs: with a function argument it binds; with no arguments it triggers. Modern jQuery splits those roles explicitly — .on("mousemove", handler) for binding and .trigger("mousemove") for firing. This page documents the shorthand API and shows how to migrate.
Concept
Understanding the .mousemove() Method
The official jQuery API describes .mousemove() as a way to bind an event handler to the mousemove event, or trigger that event on an element. When you pass a handler, jQuery registers it on each matched element and calls it whenever the pointer moves inside that element — often many times per second. Handlers typically read event.pageX and event.pageY for coordinates.
When you call .mousemove() with no arguments, jQuery synthetically fires the mousemove event on each matched element. Bound handlers run immediately. This trigger behavior is equivalent to .trigger("mousemove").
⚠️
Deprecated since jQuery 3.3
Do not use .mousemove(handler) or .mousemove(eventData, handler) in new code. Replace them with .on("mousemove", handler) or .on("mousemove", eventData, handler). Replace no-argument .mousemove() with .trigger("mousemove"). For drag patterns, performance tips, and coordinate details, read the jQuery mousemove event tutorial.
Foundation
📝 Syntax
The .mousemove() method has three signatures from the official jQuery API. The binding forms are deprecated; the trigger form remains valid but .trigger("mousemove") is preferred:
event.pageX and event.pageY inside handler — same in legacy and modern
Trigger mousemove programmatically
$("#target").mousemove()
$("#target").trigger("mousemove")
Remove mousemove handlers
$("#target").off("mousemove")
Delegated mousemove on children
$("#canvas").on("mousemove", ".handle", fn) — not available via .mousemove()
Drag pattern: bind on press
$("#box").mousedown(function(){ $(document).mousemove(drag); }) — legacy shorthand; prefer .on() for new code
Compare
📋 .mousemove() vs .on("mousemove") vs .trigger("mousemove") vs .off("mousemove")
Four related APIs — know which one binds, which one fires, and which one cleans up after drag tracking.
.mousemove()
deprecated
Legacy bind (.mousemove(fn)) or trigger (.mousemove()) — use modern APIs for new code
.on("mousemove")
bind
Modern binding since 1.7 — supports eventData and delegation on dynamic elements
.trigger("mousemove")
fire
Programmatically run handlers — clearer than no-arg .mousemove()
.off("mousemove")
cleanup
Remove handlers after drag ends — essential when binding on document during mousedown
Hands-On
Examples Gallery
Five examples cover binding, eventData, triggering, migration from .mousemove() to .on("mousemove"), and legacy drag tracking with .mousedown() + .mousemove(). Use the Try-it links to run each snippet in the browser. Remember: binding with .mousemove(handler) is deprecated — these demos show legacy syntax you will encounter in older code.
📚 Binding & Triggering
Legacy .mousemove() signatures for binding handlers and firing events programmatically.
Example 1 — Bind Handler with .mousemove(handler)
The canonical legacy pattern — log event.pageX and event.pageY whenever the pointer moves over #target.
Move over #target → log updates with pageX and pageY
Values change continuously as the pointer moves
Deprecated — prefer .on("mousemove", fn) for new code
How It Works
.mousemove(fn) registers the function on the element. jQuery internally routes this to .on("mousemove", fn). The handler runs on every pixel movement inside #target.
Example 2 — Pass eventData with .mousemove(eventData, handler)
Since jQuery 1.4.3, pass an object before the handler — it arrives as event.data.
Move over #target → "mode: track | pageX: 120, pageY: 85"
event.data.mode comes from { mode: "track" }
Modern equivalent: .on("mousemove", { mode: "track" }, fn)
How It Works
jQuery stores the { mode: "track" } object and injects it into event.data on every mousemove inside #target. Modern equivalent: .on("mousemove", { mode: "track" }, fn).
Example 3 — Trigger mousemove with No-Argument .mousemove()
Calling .mousemove() without a handler fires the mousemove event programmatically from the #fire button.
Move over #target → count increments naturally
Click #fire → $("#target").mousemove() → same handler runs
No-arg .mousemove() is trigger shorthand — prefer .trigger("mousemove")
How It Works
The first .mousemove(function(){ ... }) binds a handler on #target. The click handler on #fire calls $("#target").mousemove() with no arguments — that synthetically fires mousemove. Replace with $("#target").trigger("mousemove") for clarity.
📈 Migration & Legacy Drag
Compare legacy and modern APIs, and track pointer movement during drag with deprecated shorthand methods.
Example 4 — Migration: .mousemove(fn) vs .on("mousemove", fn)
Both bind the same mousemove event — .on() is the recommended API for new code.
Move over #legacy → legacy deprecation message with pageX
Move over #modern → modern .on("mousemove") message with pageX
Behavior is identical — only the API name differs
How It Works
Under the hood, .mousemove(fn) calls .on("mousemove", fn). Migration is a straight rename with no behavior change for simple bindings. The advantage of .on() is delegation — $("#canvas").on("mousemove", ".handle", fn) — which .mousemove() cannot do.
Example 5 — Legacy Drag with .mousedown() + .mousemove() on Document
Bind .mousemove() on document during press, then .off("mousemove") on mouseup — a classic legacy drag pattern using deprecated shorthand methods.
Press left button on #box → $(document).mousemove(onMove)
Drag anywhere → box follows cursor via pageX/pageY
Release anywhere → $(document).off("mousemove", onMove)
Migrate to .on("mousedown") / .on("mousemove") / .off("mousemove") in new code
How It Works
Binding mousemove permanently would waste CPU. Legacy code binds on .mousedown(), attaches .mousemove(onMove) to document for global tracking, and uses $(document).one("mouseup", ...) with .off("mousemove", onMove) to stop — even if the user releases outside #box. Both .mousedown() and .mousemove() binding forms are deprecated — migrate to .on() and .off().
Applications
🚀 Common Use Cases
Reading legacy code — recognize $("#canvas").mousemove(fn) as equivalent to .on("mousemove", fn) in older drag libraries.
Coordinate tracking — legacy code uses .mousemove(fn) to read event.pageX and event.pageY — migrate to .on("mousemove", fn).
Drag pairs — chain .mousedown(fn).mousemove(drag) on document — unbind with .off("mousemove") on mouseup.
Automated testing — test suites may call .mousemove() to simulate movement — consider .trigger("mousemove") for explicit intent.
🧠 How .mousemove() Routes Through jQuery
1
You call .mousemove()
With a function argument, jQuery treats it as a bind request. With no arguments, it treats it as a trigger request.
dispatch
2
Bind path
.mousemove(handler) delegates internally to .on("mousemove", handler) — the handler is stored in jQuery’s event system.
.on("mousemove")
3
Trigger path
No-arg .mousemove() delegates to .trigger("mousemove") — bound handlers run on each matched element.
.trigger("mousemove")
4
👉
jQuery object returned
Both paths return the original collection for chaining — .mousemove(fn).css("cursor", "crosshair") works the same as .on("mousemove", fn).css("cursor", "crosshair").
Important
📝 Notes
Deprecated since jQuery 3.3 — do not use .mousemove(handler) or .mousemove(eventData, handler) in new code. Use .on("mousemove") instead.
Bind with .mousemove(handler) since jQuery 1.0; eventData form since 1.4.3.
No-argument .mousemove() triggers the event since jQuery 1.0 — prefer .trigger("mousemove").
.mousemove() does not support event delegation — use .on("mousemove", selector, fn) for dynamic elements.
mousemove is high-frequency — keep handlers lightweight and unbind with .off("mousemove") when tracking ends.
Remove handlers with .off("mousemove") — not by calling .mousemove(undefined).
Legacy code using .mousemove() still runs in jQuery 3.x — migrate when you refactor those files.
For the full modern mousemove guide — drag patterns, coordinates, and performance — see the jQuery mousemove event tutorial.
Compatibility
Browser Support
jQuery normalizes the mousemove event in every browser it supports. The .mousemove() method itself is a jQuery API — it works in jQuery 1.x, 2.x, and 3.x. Binding via .mousemove(handler) is deprecated since 3.3 but still functional; triggering via no-arg .mousemove() also remains supported.
✓ jQuery 1.0+
jQuery .mousemove() method
Supported across all jQuery versions you are likely to maintain. Deprecated binding since 3.3 — use .on('mousemove') for new projects. Native equivalent for binding: element.addEventListener('mousemove', fn).
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
.mousemove()Legacy API
Bottom line: Safe in legacy jQuery projects. Migrate bindings to .on('mousemove') and triggers to .trigger('mousemove') when updating code.
Wrap Up
Conclusion
The jQuery .mousemove() method is the legacy shorthand for binding and triggering mousemove handlers. Use .mousemove(handler) or .mousemove(eventData, handler) to bind — both deprecated since jQuery 3.3. Use no-argument .mousemove() to trigger — equivalent to .trigger("mousemove").
For new code, prefer .on("mousemove", fn) for binding and .trigger("mousemove") for programmatic firing. When you encounter .mousemove() in older projects, recognize it, understand it, and migrate when practical. For drag patterns, coordinates, and performance tips, continue with the jQuery mousemove event tutorial.
Write new code with deprecated .mousemove(handler)
Leave permanent mousemove handlers on document after drag ends
Do heavy DOM work inside high-frequency mousemove handlers
Confuse .mousemove(fn) (bind) with .mousemove() (trigger)
Copy deprecated drag patterns from old tutorials without modernizing them
Summary
Key Takeaways
Knowledge Unlocked
Six things to remember about .mousemove()
Legacy bind, modern migrate.
6
Core concepts
.mm01
.mousemove(fn)
Bind
Deprecated
data02
eventData
Since 1.4.3
Handler
()03
.mousemove()
Trigger
No args
.on04
.on("mousemove")
Modern
Replace
⚡05
.trigger()
Fire
Programmatic
3.306
Deprecated
Since 3.3
Migrate
❓ Frequently Asked Questions
The .mousemove() method has two roles. With a handler argument — .mousemove(handler) or .mousemove(eventData, handler) — it binds a function that runs whenever the pointer moves inside the matched element. With no arguments — .mousemove() — it triggers the mousemove event on each matched element, running bound handlers. Both forms have been part of jQuery since 1.0; the binding form is deprecated since 3.3.
Yes — the binding signatures .mousemove(handler) and .mousemove(eventData, handler) are deprecated since jQuery 3.3. Use .on('mousemove', handler) or .on('mousemove', eventData, handler) instead. The no-argument .mousemove() trigger form still works but .trigger('mousemove') is clearer and preferred in modern code. Existing legacy code continues to run in jQuery 3.x; migrate when you touch those files.
.mousemove(handler) registers a callback — it does not fire the event immediately. .mousemove() with no arguments triggers the mousemove event programmatically on every matched element, the same as .trigger('mousemove'). The handler form is deprecated for binding; the no-arg form is a trigger shorthand. Always check whether parentheses contain a function before reading legacy jQuery code.
Replace .mousemove(fn) with .on('mousemove', fn). Replace .mousemove(data, fn) with .on('mousemove', data, fn). Replace no-arg .mousemove() with .trigger('mousemove'). Replace .unbind('mousemove') cleanup with .off('mousemove'). Under the hood, .mousemove(handler) already delegates to .on('mousemove') — migration is a straight rename with no behavior change for simple bindings.
Yes. jQuery 3.x keeps .mousemove() for backward compatibility with jQuery 1.x and 2.x codebases. It still binds and triggers correctly. The API docs mark it deprecated to steer new projects toward .on() and .trigger(). Do not use .mousemove(handler) in new code — prefer the modern API covered in the jQuery mousemove event tutorial.
Since jQuery 1.4.3, you can pass an object as the first argument before the handler. jQuery attaches it to event.data inside the callback — for example, .mousemove({ mode: 'track' }, fn) lets fn read event.data.mode. This avoids closures when the same handler serves multiple elements. The modern equivalent is .on('mousemove', { mode: 'track' }, fn).
Did you know?
The official jQuery API recommends binding mousemove only while the user is dragging — not permanently on every element. Legacy drag code often chains deprecated .mousedown(fn) with $(document).mousemove(drag) and cleans up with .off("mousemove", drag) on mouseup. That pattern exists because mouseup may fire on a different element than where mousemove was bound. When you modernize, rename to .on("mousedown"), .on("mousemove"), and .off("mousemove") — the logic stays the same.