jQuery mousedown Event

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

Definition

mousedown is sent when the mouse button is pressed while the pointer is over an element — before release. Bind it with .on("mousedown", handler) (jQuery 1.7+).

Syntax

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

jQuery
$("#target").on("mousedown", function () { ... })
$("#target").trigger("mousedown")

// Fires on press (any button)
// Prefer on/trigger — not the deprecated .mousedown()
// Left button: event.which === 1
CallWhat it does
mousedownLearn the jQuery mousedown event: bind with .on(\

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

Parameters

ParameterDescription
Step 1Select the element(s): $("#box"), $("p"), etc.
Step 2Bind: .on("mousedown", function (event) { ... }).
Step 3Optional: gate on event.which === 1 for the left button.

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 a mousedown Handler

Official style: .on("mousedown", …) on a target element.

jQuery
$("#target").on("mousedown", function () {
  console.log("Handler for mousedown called.");
});
Try It Yourself

How It Works

  1. Select #target.
  2. Bind with .on("mousedown", handler).
  3. User presses a mouse button over the element.

Example 2 — Trigger mousedown from Code

Fire the same handlers with a single click on another control.

jQuery
$("#target").on("mousedown", function () {
  console.log("Handler for mousedown called.");
});

$("#other").on("click", function () {
  $("#target").trigger("mousedown");
});
Try It Yourself

How It Works

  1. Bind the real handler on #target.
  2. Another control listens for its own click.
  3. trigger("mousedown") runs #target’s handlers.

Example 3 — Left Button Only (event.which)

Official tip: start drag-like actions only on the primary button.

jQuery
$("#box").on("mousedown", function (event) {
  if (event.which !== 1) {
    return; // ignore middle / right
  }
  console.log("Primary button pressed");
});
Try It Yourself

How It Works

  1. which is normalized by jQuery: 1 / 2 / 3.
  2. Return early if it is not the left button.
  3. Right-click menus stay usable.

Frequently Asked Questions

mousedown fires when the mouse button is pressed while the pointer is over an element — before release. Bind with .on("mousedown", handler) (jQuery 1.7+). Any HTML element can receive it.
Prefer .on("mousedown", handler). The .mousedown(handler) shorthand is deprecated since jQuery 3.3. To fire the event, use .trigger("mousedown") instead of .mousedown().
mousedown fires on press. click needs press and release inside the same element. If the user presses inside then releases outside, mousedown still fired but click does not.
jQuery normalizes event.which: 1 = left, 2 = middle, 3 = right. Use which === 1 to start drags only on the primary button so right-click context menus are not disrupted.
Call $(selector).trigger("mousedown"). That runs bound handlers. Use .triggerHandler("mousedown") to run handlers without default browser behavior.
event.which === 3 means right button, but it is not fully reliable in every browser. Prefer the contextmenu event for custom right-click menus.

Next: .mousedown() Method — Deprecated Shorthand

See the deprecated helper and how it maps to on / trigger.

.mousedown() Method — Deprecated Shorthand 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