The .trigger() method programmatically executes handlers bound with .on(). Use it to simulate clicks, fire custom events, pass runtime data to handlers, and chain UI actions — all without waiting for user input. This tutorial covers official signatures, five worked examples, and comparison with .triggerHandler().
01
Syntax
.trigger(type)
02
Handlers
Runs .on() fns
03
Extra args
[, params]
04
Custom
Any event name
05
Bubbles
Since 1.3
06
Since 1.0
Core API
Fundamentals
Introduction
Events usually start with user action — a click, a keypress, a form submit. But your code often needs to fire those same handlers programmatically: auto-submit after validation, simulate a button click from another control, or notify components through a custom event name.
jQuery’s .trigger() method (available since 1.0) runs every handler registered for the given event type on the matched elements, in the same order they would run if the event occurred naturally. Since jQuery 1.3, triggered events bubble up the DOM tree just like real browser events.
Concept
Understanding .trigger()
Binding and triggering are two halves of the same pattern. You attach a handler with .on("click", fn); later, .trigger("click") invokes fn without the user clicking. jQuery builds a synthesized event object and passes it as the first argument to each handler.
The second argument to .trigger() lets you pass extra parameters determined at trigger time. This differs from eventData passed to .on() at bind time — both reach the handler, but through different mechanisms and at different stages.
💡
Beginner Tip
To run jQuery handlers without native browser side effects (like following a link or submitting a form), use .triggerHandler() instead. .trigger("submit") may also invoke the browser’s default submit behavior.
Handler return values are collected; if any handler returns false, the returned jQuery object reflects that.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Trigger click handlers
$("#btn").trigger("click")
Pass extra args to handler
$("p").trigger("click", ["foo", "bar"])
Fire custom event
$("#app").trigger("refresh")
Custom event + data
$("#foo").trigger("custom", ["A", "B"])
Trigger with Event object
$(form).trigger(jQuery.Event("submit"))
jQuery-only (no native)
$("#btn").triggerHandler("click")
Added in
jQuery 1.0 (Event obj 1.3)
Compare
📋 .trigger() vs .triggerHandler() vs shorthand methods
Three ways to programmatically invoke event behavior. Choose based on whether you need bubbling, native actions, or jQuery-only handlers.
.trigger()
Bubbles
Runs handlers + may invoke native behavior
.triggerHandler()
No bubble
First element only, jQuery handlers only
.click()
Shorthand
Bind or trigger click — see click tutorial
.on()
Bind
Attach handlers that .trigger() will run
Hands-On
Examples Gallery
All five examples follow the official jQuery API documentation for .trigger(). Use the Try-it links to fire events and watch handlers run programmatically.
📚 Official API Examples
Five patterns from api.jquery.com/trigger/.
Example 1 — Button #2 Triggers Click on Button #1
Official interactive demo: clicking the second button programmatically triggers the first button’s click handler.
Click Button #1 → span #1 counter increments
Click Button #2 → triggers Button #1 handler + span #2 increments
Both counters can increase from one Button #2 click
How It Works
.trigger("click") executes bound handlers in registration order. Button #2’s handler chains into Button #1’s logic without simulating a physical click on Button #1.
Example 2 — Trigger a Bound Click Handler on #foo
The canonical bind-then-trigger pattern from the API docs.
Page load → trigger("click") fires immediately
Alert shows #foo text without user click
Manual clicks also run the same handler
How It Works
Handlers attached with .on() respond identically whether the event is user-generated or triggered in code. Order of execution matches natural event delivery.
Example 3 — Trigger a Custom Event with Parameters
Bind a custom event name and pass an array of values at trigger time.
trigger("custom", ["Custom", "Event"])
Alert shows:
Custom
Event
param1 and param2 follow the event object in the handler
How It Works
Custom event names work like browser events for jQuery’s purposes. Extra trigger parameters become handler arguments after event — unlike eventData from .on(), which lives on event.data.
Example 4 — Pass Arbitrary Data on a Standard Click
Official pattern: extra parameters on .trigger() override undefined handler args from normal clicks.
jQuery
$( "p" )
.on( "click", function( event, a, b ) {
// Normal click: a and b are undefined
// trigger below: a is "foo", b is "bar"
alert( "a=" + a + ", b=" + b );
} )
.trigger( "click", [ "foo", "bar" ] );
trigger("click", ["foo", "bar"]) → alert "a=foo, b=bar"
User click on p → alert "a=undefined, b=undefined"
Same handler, different data sources
How It Works
extraParameters from .trigger() are determined at fire time. eventData from .on("click", { ... }, fn) is fixed at bind time and appears on event.data instead.
Example 5 — Trigger with a jQuery.Event Object
Create a custom event object, attach properties, trigger it, and inspect isDefaultPrevented().
jQuery.Event("logged") with .user and .pass
Handler reads custom properties from event object
preventDefault() → isDefaultPrevented() is true after trigger
How It Works
Passing an event object gives full control before triggering. Handlers can call preventDefault() or stopPropagation(); the caller inspects the same object afterward.
Applications
🚀 Common Use Cases
Chained UI actions — one button triggers another element’s click handler.
Form workflows — validate in code, then $("form").trigger("submit").
Component pub/sub — $("#app").trigger("dataLoaded", [payload]) between modules.
Testing & demos — fire events in Try-it labs without manual clicks.
Auto-initialization — trigger a custom "ready" event after plugin setup.
Keyboard shortcuts — map a keypress to $("#save").trigger("click").
🧠 How .trigger() Executes Handlers
1
Build event
jQuery creates or accepts an event object for the requested type and attaches any extra parameters you pass.
Create
2
Run handlers
All matching handlers on the element execute in bind order, receiving the event object plus extra parameters.
Invoke
3
Bubble up
Since jQuery 1.3, the event bubbles through ancestors unless stopped with return false or stopPropagation().
Bubble
4
⚡
Native action
Unless prevented, default browser behavior may also run — use .triggerHandler() when you want to skip native side effects.
Important
📝 Notes
.trigger() has existed since jQuery 1.0; event object support since 1.3; single-value extraParameters since 1.6.2.
Triggered events bubble (since 1.3) but do not perfectly replicate every detail of user-generated events.
extraParameters to .trigger() differ from eventData to .on() — bind-time vs trigger-time data.
On plain objects and DOM nodes, if the event name matches a property (e.g. onclick), jQuery may invoke it unless preventDefault() is called.
For objects with a length property that are not array-like, wrap in an array: .trigger("evt", [{ length: 1 }]).
.trigger() works on plain JavaScript objects wrapped in jQuery for pub/sub-style messaging.
Compatibility
Browser Support
.trigger() is a jQuery method available since jQuery 1.0 in all jQuery 1.x, 2.x, and 3.x releases. It works in every browser your jQuery version supports. Native equivalent: element.dispatchEvent(new Event('click')) — but without jQuery's handler registry, extra parameters, or custom event conveniences.
✓ jQuery 1.0+
jQuery .trigger()
Supported in jQuery 1.0+ across all modern browsers and IE with supported jQuery builds. The standard way to programmatically fire jQuery-bound events.
100%Core jQuery API
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
.trigger()Universal
Bottom line: Use .trigger() to run .on() handlers from code. Pass extra parameters when handlers need runtime data. Prefer .triggerHandler() when native browser actions must not run.
Wrap Up
Conclusion
jQuery .trigger() closes the loop with .on(): bind handlers to react to events, then fire those same handlers from code when your application logic requires it. Custom events, extra parameters, and jQuery.Event objects make it flexible for real-world UI orchestration.
Remember the distinction between trigger-time parameters and bind-time eventData, and reach for .triggerHandler() when you need jQuery-only behavior. The click event tutorial shows .trigger("click") in a full mouse-event context.
Use custom event names for decoupled component communication
Pass runtime data via .trigger(type, [a, b]) when needed at fire time
Use jQuery.Event() when you need to inspect isDefaultPrevented() after
Prefer .triggerHandler() to avoid unwanted native submit/click behavior
Keep handler logic in named functions reusable by both user events and triggers
❌ Don’t
Assume .trigger() perfectly simulates real user interaction for all tests
Confuse .trigger() extra params with .on() eventData
Trigger submit on forms without understanding native submit may also run
Create infinite trigger loops (A triggers B triggers A)
Trigger events on elements with no bound handlers and expect side effects
Summary
Key Takeaways
Knowledge Unlocked
Six things to remember about .trigger()
Fire events from code.
6
Core concepts
⚡01
Fire
Run .on() handlers.
Core
[ ]02
Extra args
At trigger time.
Data
custom03
Custom
Any event name.
Pub/sub
↑04
Bubbles
Since 1.3.
DOM
Event05
jQuery.Event
Full control.
Advanced
H06
Handler
No native fx.
Alt API
❓ Frequently Asked Questions
.trigger() executes all handlers attached with .on() (or shortcut methods) for the given event type on the matched elements. It simulates an event activation programmatically — useful for testing, chaining actions, or firing custom events without user input.
.click() and .submit() are shorthand methods that may also invoke native browser behavior. .trigger('click') runs jQuery handlers and can bubble up the DOM (since 1.3). Use .triggerHandler() if you only want jQuery handlers without native side effects.
Pass an array as the second argument: .trigger('click', ['foo', 'bar']). Extra values arrive as parameters after the event object in the handler: function(event, a, b). This is different from eventData passed to .on() at bind time.
.trigger() fires handlers on matched elements and bubbles (like a real event). .triggerHandler() runs handlers on only the first matched element, does not bubble, and does not invoke native default actions — ideal when you want jQuery-only behavior.
Yes. Bind with .on('myEvent', fn) and fire with .trigger('myEvent') or .trigger('myEvent', [extraData]). Custom events are useful for pub/sub patterns between components.
No. .trigger() creates a synthesized jQuery event object and runs handlers in the same order as a natural event, but it does not perfectly replicate every browser detail of a real user interaction. For testing native behavior, user actions or integration tests may be needed.
Did you know?
Before jQuery 1.3, .trigger() did not bubble triggered events up the DOM. That change made programmatic events behave much closer to real user events — delegated handlers on parent elements now respond to .trigger() on children, just as they do to actual clicks.