.click() is a shorthand for binding or triggering the click event. 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.
.click() with no arguments fires the event — prefer .trigger("click").
jQuery
$("#target").click(function () {
console.log("Handler for click called.");
});
$("#fire").click(function () {
$("#target").click(); // same idea as .trigger("click")
});
With a handler — .click(handler) or .click(eventData, handler) — it binds a click callback. With no arguments — .click() — it triggers click on each matched element. The binding forms are deprecated since jQuery 3.3.
Yes. Prefer .on("click", handler) or .on("click", eventData, handler) to bind, and .trigger("click") to fire. jQuery 3.x still runs .click() for compatibility.
.click(handler) only registers a callback. .click() with no arguments triggers the event (same idea as .trigger("click")).
Replace .click(fn) with .on("click", fn). Replace .click(data, fn) with .on("click", data, fn). Replace no-arg .click() with .trigger("click").
Yes for legacy code. It still works, but new code should use .on / .trigger. See the click event tutorial for the modern API.
Since 1.4.3 you can pass data before the handler. It appears as event.data inside the callback. Modern form: .on("click", eventData, handler).