jQuery .mousemove() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Mouse Events

Definition

.mousemove() is jQuery’s legacy shorthand for the mousemove event (since 1.0). Pass a handler to bind; call it with no arguments to trigger. Binding forms are deprecated since 3.3 — prefer .on() / .trigger().

Syntax

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

jQuery
$("#box").mousemove(fn)              // bind (deprecated)
$("#box").mousemove({ mode: "x" }, fn) // bind + eventData (deprecated)
$("#box").mousemove()                // trigger (prefer .trigger)

// Modern:
$("#box").on("mousemove", fn)
$("#box").trigger("mousemove")
CallWhat it does
.mousemove()Learn jQuery .mousemove(): bind handlers, pass eventData, trigger with no args, migrate to .on('mousemove') and .trigger('mousemove'), examples, pitfalls, and FAQs. Deprecated since 3.3.

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

Parameters

ParameterDescription
Step 1Decide if the call is a bind (function passed) or a trigger (no args).
Step 2For new work, use .on("mousemove", handler) instead of .mousemove(handler).
Step 3Replace no-arg .mousemove() with .trigger("mousemove").

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Bind with .mousemove(handler)

Log document coordinates with the deprecated binding shorthand.

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

// Prefer: $("#target").on("mousemove", function (event) { … });
Try It Yourself

How It Works

  1. Pass a function. .mousemove(fn) registers the handler (deprecated).
  2. Move inside the element. Each movement calls the function.
  3. Read coords. Use normalized pageX / pageY.

Example 2 — Pass eventData

Since 1.4.3, pass an object before the handler — available as event.data.

jQuery
$("#target").mousemove({ mode: "track" }, function (event) {
  $("#log").text(
    "mode: " + event.data.mode +
    " | pageX: " + event.pageX
  );
});

// Prefer: .on("mousemove", { mode: "track" }, fn)
Try It Yourself

How It Works

  1. First argument is data. { mode: "track" } is not the handler.
  2. Second argument is the function. It runs on each move.
  3. Read event.data. Avoids an extra closure for shared config.

Example 3 — Trigger with No Arguments

Call .mousemove() with no args to fire bound handlers programmatically.

jQuery
var count = 0;

$("#target").mousemove(function () {
  count++;
  $("#log").text("Handler fired (count: " + count + ")");
});

$("#fire").on("click", function () {
  $("#target").mousemove();  // prefer .trigger("mousemove")
});
Try It Yourself

How It Works

  1. Bind first. A handler must exist for the trigger to do anything useful.
  2. Empty call fires. .mousemove() synthesizes the event.
  3. Same handlers run. Real moves and triggers share the callback.

Frequently Asked Questions

With a handler — .mousemove(fn) or .mousemove(eventData, fn) — it binds a function that runs when the pointer moves inside the element. With no arguments — .mousemove() — it triggers the mousemove event. Binding forms are deprecated since jQuery 3.3.
Yes. Prefer .on('mousemove', handler) for binding and .trigger('mousemove') for firing. jQuery 3.x still runs the shorthand for compatibility; migrate when you touch legacy code.
.mousemove(fn) only registers a callback. .mousemove() with no arguments fires the event on each matched element (same idea as .trigger('mousemove')). Check whether a function is passed before reading old code.
Replace .mousemove(fn) with .on('mousemove', fn). Replace .mousemove(data, fn) with .on('mousemove', data, fn). Replace no-arg .mousemove() with .trigger('mousemove'). Unbind with .off('mousemove'). Behavior for simple bindings is the same.
Yes for backward compatibility. It still binds and triggers correctly. Do not use it in new projects — use the modern mousemove event API instead.
Since 1.4.3 you can pass an object before the handler. It appears as event.data inside the callback. The modern form is .on('mousemove', eventData, handler).

Next: mouseout Event — Leave Detection & Bubbling

Learn when the pointer leaves an element — and how it differs from mouseleave.

mouseout Event — Leave Detection & Bubbling 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