.mousedown() is a shorthand for binding or triggering the mousedown event (button press). With a handler it binds; with no arguments it triggers. Prefer .on / .trigger in new code.
Syntax
Start with these common calls. Keep them short and readable.
Learn the deprecated jQuery .mousedown() shorthand: bind with .mousedown(handler), pass eventData, trigger with no-arg .mousedown(), and migrate to .on(\
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
.mousedown() with no arguments fires the event — prefer .trigger("mousedown").
jQuery
$("#target").mousedown(function () {
console.log("Handler for mousedown called.");
});
$("#fire").click(function () {
$("#target").mousedown(); // same idea as .trigger("mousedown")
});
With a handler — .mousedown(handler) or .mousedown(eventData, handler) — it binds a callback that runs when a mouse button is pressed over the element. With no arguments — .mousedown() — it triggers mousedown on each matched element. Binding forms are deprecated since jQuery 3.3.
Yes. Prefer .on("mousedown", handler) or .on("mousedown", eventData, handler) to bind, and .trigger("mousedown") to fire. jQuery 3.x still runs .mousedown() for compatibility.
.mousedown(handler) only registers a callback. .mousedown() with no arguments triggers the event (same idea as .trigger("mousedown")).
Replace .mousedown(fn) with .on("mousedown", fn). Replace .mousedown(data, fn) with .on("mousedown", data, fn). Replace no-arg .mousedown() with .trigger("mousedown").
mousedown fires when the button is pressed (before release). click fires after a press-and-release on the same element. Prefer click for most UI actions; use mousedown when you need press-start behavior (for example, starting a drag).
Since 1.4.3 you can pass data before the handler. It appears as event.data inside the callback. Modern form: .on("mousedown", eventData, handler).