jQuery Click Event

Beginner
6 min read
Updated: Oct 2026
4 examples
Live preview

What Is the click Event?

click is sent when the mouse button is pressed and released while the pointer stays inside an element. Bind it with .on("click", handler) (jQuery 1.7+).

Remember
$("#target").on("click", function () { ... })
$("#target").trigger("click")

// Needs: mousedown + mouseup inside the element
// Prefer on/trigger — not the deprecated .click()
NeedUse
Bind handler.on("click", handler)
Fire event.trigger("click")
Delegation.on("click", "li", handler)
Press onlymousedown

How to Use click

Select an element, bind with .on, optionally trigger from code.

  1. Select the element(s): $("#btn"), $("p"), etc.
  2. Bind: .on("click", function (event) { ... }).
  3. Use $(this) for the bound element; read event for details.
  4. To fire in code: .trigger("click"). Unbind with .off("click").
PieceRequired?Role
"click"YesEvent type string for .on / .trigger
handlerYes (bind)Runs on each click
eventDataOptionalExtra data passed into the handler
Return value—jQuery set (chainable)

Pseudocode

Pseudocode
function onClick(element, handler):
    when mouse down inside element
     and mouse up inside element:
        handler(event)

trigger(element, "click"):
    run all click handlers on element
    (may also run default browser action)

Cheat Sheet

Keep these facts handy while wiring click handlers.

TopicDetail
Bind.on("click", handler) (1.7+)
Trigger.trigger("click") (1.0+)
SequencePress + release inside the element
Delegation.on("click", childSelector, fn)
Unbind.off("click")
Deprecated.click() shorthand (3.3+)

Live Preview

Click the demo control (or use presets) to see on("click") in action.

Uses .on("click") and .trigger("click") — same ideas as the examples below.

Result
Handler for click called.

jQuery Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Bind a Click Handler

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

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

How It Works

  1. Select #target.
  2. Bind with .on("click", handler).
  3. User clicks — press and release inside the element.
  4. Handler runs once per completed click.

Example 2 — Trigger a Click from Code

Fire the same handlers without a real mouse click.

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

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

How It Works

  1. Bind the real handler on #target.
  2. Another control listens for its own click.
  3. trigger("click") runs #target’s click handlers.
  4. Same message as a user click on #target.

Example 3 — Event Delegation

One parent handler covers current and future children.

jQuery
$("#list").on("click", "li", function () {
  console.log("Clicked: " + $(this).text());
});

// Later…
$("#list").append("<li>New item</li>");
// New item is clickable too — no extra bind
Try It Yourself

How It Works

  1. Bind on parent #list, filter with "li".
  2. Click bubbles from the li (or its children) to the list.
  3. this is the matched li.
  4. New items work automatically after append.

Example 4 — Hide Paragraphs on Click

Official demo idea: each paragraph hides itself when clicked.

jQuery
$("p").on("click", function () {
  $(this).hide();
});
Try It Yourself

How It Works

  1. Bind click on every p.
  2. this is the paragraph that was clicked.
  3. hide() removes it from view.
  4. Each click affects only that paragraph.

Edge Cases & Pitfalls

Watch these when relying on click handlers.

deprecated

Avoid .click() shorthand

Deprecated in 3.3. Use .on("click") / .trigger("click") / .off("click").

sequence

Incomplete press/release skips click

If the pointer leaves before release, you may get mousedown/mouseup without click. Use those events when that matters.

dynamic

New DOM nodes need delegation

Binding only existing elements misses later inserts. Prefer .on("click", "child", fn) on a stable parent.

target

this ≠ always event.target

Clicks on nested spans/icons set event.target to the child. Use this (or event.currentTarget) for the bound element.

Browser Support

The native click event works in all browsers. Bind with .on("click") since jQuery 1.7; .trigger("click") since 1.0. Prefer these over the deprecated .click() shorthand (3.3+).

✓ jQuery 1.7+ (.on)

click event

Supported everywhere jQuery event APIs run in the browser. Use on/trigger for modern code.

100% Browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
on("click") Excellent

Bottom line: Bind with .on("click", fn). Trigger with .trigger("click"). Use delegation for dynamic lists.

Performance Notes

ApproachCostBest for
Direct .on("click")1 handler / elementFew static controls
Delegated .on1 handler / parentLists / tables / dynamic UI
Many direct bindsHigher memoryAvoid on large collections

Delegation scales better than binding hundreds of individual click handlers. Always .off when removing long-lived widgets to avoid leaks.

Key Takeaways

  • Bind: .on("click", handler) — not deprecated .click().
  • Fire: .trigger("click") for programmatic clicks.
  • Delegate: one parent handler for dynamic children.
  • Sequence: needs press + release inside the element.

One line: use .on("click", fn) to listen and .trigger("click") to fire — prefer that over the deprecated .click() shorthand.

Frequently Asked Questions

click fires when the mouse button is pressed and released while the pointer stays inside the element. Bind with .on("click", handler) (jQuery 1.7+). Any HTML element can receive it.
Prefer .on("click", handler). The .click(handler) shorthand is deprecated since jQuery 3.3. To fire the event, use .trigger("click") instead of .click().
click needs both press and release inside the same element. mousedown fires on press; mouseup on release. Use mousedown/mouseup when you do not need the full click sequence.
Call $(selector).trigger("click"). That runs bound handlers (and default actions). Use .triggerHandler("click") to run handlers without default browser behavior.
Bind once on a parent: $("#list").on("click", "li", fn). Clicks on matching children (including ones added later) bubble to the parent and run the handler.
this is the element the handler is bound to (or the matched child with delegation). event.target is the deepest node actually clicked — often a child inside this.

Next: .click() shorthand

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

.click() tutorial →

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