The mousedown event fires when the user presses a mouse button over an element — before release. This tutorial covers binding with .on("mousedown"), triggering with .trigger("mousedown"), detecting buttons with event.which, pairing with mouseup, and comparing mousedown with click.
01
.on()
Bind handler
02
.trigger()
Fire mousedown
03
event.which
Button ID
04
vs click
Press only
05
mouseup
Press + release
06
Since 1.7
Modern API
Fundamentals
Introduction
Most interactive pages respond to click — the full press-and-release gesture. Sometimes you need to react earlier: the instant the user presses the mouse button, before they release it. That is what mousedown is for — drag handles, drawing tools, press-and-hold menus, and custom sliders all start on mousedown.
The official jQuery API distinguishes the mousedownevent (bound with .on("mousedown") since 1.7) from the deprecated .mousedown()method used in older code. To programmatically fire a handler, use .trigger("mousedown") — available since jQuery 1.0. Any HTML element can receive the mousedown event.
Concept
Understanding the mousedown Event
The mousedown event is sent to an element when the mouse pointer is over the element and the mouse button is pressed. jQuery normalizes this across browsers and gives you a consistent event object with properties like event.which, event.pageX, and event.preventDefault().
Any mouse button triggers mousedown — left, middle, or right. Use event.which to filter: 1 = left, 2 = middle, 3 = right. jQuery normalizes this property so it works in every browser. If the user presses inside an element but drags away and releases outside, mousedown still fired — most UIs treat that as canceling the press, and no click fires on that element.
💡
Beginner Tip
Default to click for buttons, links, and toggles. Reach for mousedown only when you need action on press — before release — such as starting a drag, showing a ripple effect, or pairing with mouseup on the document for a complete gesture.
Foundation
📝 Syntax
The modern jQuery API for the mousedown event has two main forms — binding a handler and triggering the event:
.on() and .trigger() return the original jQuery object for chaining.
Handler return values are ignored unless you use return false (equivalent to preventDefault() + stopPropagation()).
Cheat Sheet
⚡ Quick Reference
Goal
Code
Bind mousedown handler
$("#box").on("mousedown", fn)
Left button only
if (event.which !== 1) return;
Pass data to handler
$("#box").on("mousedown", { id: 1 }, fn)
Delegated mousedown on children
$("#panel").on("mousedown", ".handle", fn)
Trigger mousedown programmatically
$("#target").trigger("mousedown")
Pair press and release
.on("mousedown", down).on("mouseup", up)
Remove mousedown handlers
$("#box").off("mousedown")
Compare
📋 mousedown vs click vs mouseup vs deprecated .mousedown()
Four ways to respond to mouse button interaction — choose the event that matches the moment in the gesture you need.
mousedown
press
Fires when button is pressed — before release; ideal for drag start
mouseup
release
Fires when button is released — regardless of where press started
click
down+up
Full press-and-release inside element — default for buttons and links
.mousedown() method
deprecated
Old binding shorthand — use .on("mousedown") instead
Hands-On
Examples Gallery
Examples 1–3 follow the official jQuery API documentation. Examples 4–5 cover event.which button detection and the difference between mousedown and click. Use the Try-it links to run each snippet in the browser.
📚 Binding & Triggering
Official jQuery demos for mousedown handlers and programmatic triggers.
Example 1 — Official Demo: Bind Handler on #target
Alert when the user presses the mouse button on the target element — the canonical .on("mousedown") pattern.
User presses mouse on #target → alert: "Handler for mousedown called."
Fires on press — before the button is released
How It Works
.on("mousedown", fn) registers the function on the element. jQuery calls it the moment the browser fires mousedown — when the pointer is over the element and the button goes down.
Example 2 — Official Demo: #other Triggers mousedown on #target
One element programmatically fires the mousedown handler on another — note the official API uses click on #other to trigger mousedown on #target.
.trigger("mousedown") synthetically fires the mousedown event on #target, running the same handler as a physical press. The official demo binds click on the trigger button — any event can call .trigger("mousedown").
Example 3 — Official Demo: Show Text on mousedown and mouseup
Append “Mouse down.” on press and “Mouse up.” on release — the official API demo for pairing both events.
Press and release on a paragraph:
"Press mouse and release here. Mouse down. Mouse up."
Each press/release cycle appends both labels
How It Works
Chaining .on("mouseup") and .on("mousedown") on the same collection registers both handlers on every matched paragraph. Press appends “Mouse down.”; release appends “Mouse up.” — order follows the user’s physical gesture.
📈 Button Detection & Gesture Timing
Patterns from the official API notes — filter by button and understand when mousedown beats click.
Example 4 — Left Button Only with event.which
Start a drag only when the primary (left) button is pressed — ignore middle and right clicks as the official API recommends.
jQuery
$( "#drag-box" ).on( "mousedown", function( event ) {
if ( event.which !== 1 ) {
return; // not the left button
}
$( this ).addClass( "dragging" );
$( document ).one( "mouseup", function() {
$( "#drag-box" ).removeClass( "dragging" );
} );
} );
Left-click #drag-box → .dragging class added until mouseup anywhere
Right-click or middle-click → ignored (event.which !== 1)
event.which: 1=left, 2=middle, 3=right
How It Works
jQuery normalizes event.which across browsers. Checking event.which !== 1 early exits for non-primary buttons — preventing accidental drag starts when the user opens a context menu. $(document).one("mouseup", ...) cleans up when the button is released anywhere on the page.
Example 5 — mousedown vs click: Press Inside, Release Outside
Demonstrate that mousedown fires on press even if the user drags away and releases outside — but click does not.
Normal click inside #zone → both "mousedown fired" and "click fired"
Press inside, drag outside, release → only "mousedown fired"
This is why drag UIs start on mousedown, not click
How It Works
click requires mousedown and mouseup both inside the same element. Dragging away before release cancels the click — but mousedown already happened. Drag handles, sliders, and drawing canvases rely on this timing difference.
Applications
🚀 Common Use Cases
Drag start — $("#handle").on("mousedown", startDrag) with event.which === 1 check.
Drawing tools — begin a stroke on mousedown, continue on mousemove, finish on mouseup.
Press feedback — add an active class on mousedown, remove on mouseup for instant visual response.
Custom sliders — track pointer on mousedown + document mousemove/mouseup.
EventData labels — $(".node").on("mousedown", { id: 42 }, fn) to pass metadata without closures.
🧠 How the mousedown Event Fits the Click Sequence
1
Pointer over element
User moves cursor over the target — no event yet until a button is pressed.
ready
2
Button pressed
User depresses mouse button — mousedown fires immediately. Your handler can run now.
mousedown
3
Button released
User releases button — mouseup fires. May occur inside or outside the element.
mouseup
4
👉
Click (maybe)
If both down and up happened inside the same element, click fires after mouseup. Otherwise, only mousedown (and mouseup) ran.
Important
📝 Notes
Bind with .on("mousedown", handler) since jQuery 1.7 — not the deprecated .mousedown(handler) method.
Trigger with .trigger("mousedown") since jQuery 1.0.
Any mouse button triggers mousedown — filter with event.which (1=left, 2=middle, 3=right).
Right-click detection via mousedown is unreliable in some browsers — use contextmenu for custom menus.
Press inside + release outside still counts as mousedown on that element — click is canceled.
Any HTML element can receive mousedown — not limited to <button> or <a>.
Use .off("mousedown") to remove handlers — avoid deprecated .unbind("mousedown").
For standard button actions, prefer click unless you specifically need press-time behavior.
Compatibility
Browser Support
The mousedown event is a standard DOM event supported in every browser jQuery targets. jQuery’s .on("mousedown") (since 1.7) and .trigger("mousedown") (since 1.0) normalize cross-browser behavior — including event.which for button detection.
✓ jQuery 1.7+
jQuery mousedown event
Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers and IE with supported jQuery versions. Native equivalent: element.addEventListener('mousedown', fn) — jQuery adds collection binding, eventData, delegation, and .trigger() in one chainable API.
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
mousedownUniversal
Bottom line: Safe in any jQuery project. Prefer .on('mousedown') over deprecated .mousedown() for binding. Check event.which for left-button-only drag starts.
Wrap Up
Conclusion
The jQuery mousedown event fires the moment the user presses a mouse button over an element — before release. Bind handlers with .on("mousedown", fn), filter buttons with event.which, and fire handlers programmatically with .trigger("mousedown").
Remember: mousedown is the first step in the click sequence. Use it when you need immediate press-time behavior — drag starts, drawing strokes, active-state feedback. For normal buttons and links, click is usually the right choice. Pair mousedown with mouseup when you need the full press-and-release story.
Bind with .on("mousedown", handler) — the modern, delegation-capable API
Check event.which === 1 before starting drags or primary-button actions
Pair mousedown with $(document).one("mouseup", fn) for document-level release
Use click for standard button and link behavior
Call .off("mousedown") when removing elements or tearing down handlers
❌ Don’t
Use deprecated .mousedown(handler) for new code — use .on("mousedown")
Replace click with mousedown on buttons unless you need press-time behavior
Rely on mousedown with event.which === 3 for context menus — use contextmenu
Forget to unbind document-level mouseup/mousemove listeners after drag ends
Assume mousedown and click always fire together — drag-away cancels click
Summary
Key Takeaways
Knowledge Unlocked
Six things to remember about the mousedown event
Press, filter, trigger.
6
Core concepts
.on01
.on("mousedown")
Bind
API
⚡02
.trigger()
Fire
Programmatic
which03
event.which
Button
Filter
↓04
Press only
Timing
Behavior
click05
vs click
Compare
Sequence
.off06
.off("mousedown")
Unbind
Cleanup
❓ Frequently Asked Questions
The mousedown event fires when the user presses a mouse button while the pointer is over an element — before the button is released. In modern jQuery, bind handlers with .on('mousedown', handler) since version 1.7. Any HTML element can receive this event, not just buttons or links.
mousedown fires the moment the button is pressed. click fires only after both mousedown and mouseup occur inside the same element — the full press-and-release gesture. If the user presses inside an element but drags away and releases outside, mousedown still fired but click does not. Use mousedown when you need immediate feedback on press; use click for standard button actions.
Use .on('mousedown', handler) for binding. The old .mousedown(handler) shorthand still works but is deprecated since jQuery 3.3 — it wraps .on('mousedown'). For unbinding, use .off('mousedown') instead of .unbind('mousedown'). .on() also supports event delegation: .on('mousedown', 'li', fn).
event.which tells you which mouse button was pressed: 1 for the left button, 2 for the middle button, and 3 for the right button. jQuery normalizes this property across browsers (Internet Explorer historically used event.button instead). Use it to start drag operations only on the primary button — ignoring right-clicks avoids conflicting with context menus.
Call .trigger('mousedown') on the target element: $('#target').trigger('mousedown'). Available since jQuery 1.0, trigger runs bound mousedown handlers. To run handlers without bubbling or default actions, use .triggerHandler('mousedown') instead.
Technically event.which === 3 indicates a right button press, but this is not fully reliable — Opera and Safari may not detect right mouse button clicks by default. For custom context menus, use the contextmenu event (.on('contextmenu')) instead of mousedown with which === 3.
Did you know?
The official jQuery API notes that if a user clicks an element, drags away, and releases the button, the sequence is still counted as a mousedown on that element — but most user interfaces treat it as canceling the button press. That is why drag-and-drop libraries listen on mousedown to start immediately, then track mousemove and finish on mouseup — never waiting for click, which would not fire after a drag-away release.