jQuery Callbacks fire() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Invoke handlers

What You’ll Learn

The fire() method is how you run a jQuery Callbacks list — it calls every registered handler in order and passes along any arguments you supply. This tutorial covers syntax, five examples, comparisons with add() and fireWith(), and edge cases like empty or disabled lists.

01

Syntax

callbacks.fire(args)

02

add()

Register first

03

Order

FIFO execution

04

Args

Shared payload

05

fireWith()

Custom this

06

Events

Pub/sub trigger

Introduction

Callback lists are useless until something triggers them. In jQuery’s Callbacks API, that trigger is fire() (or its sibling fireWith() when you need a custom this value).

Typical flow: create a list with $.Callbacks(), register handlers via add(), then call fire() when your event occurs — data loaded, button clicked, plugin initialized. Every subscriber runs with the same arguments you pass to fire().

Understanding the fire() Method

callbacks.fire([arg1 [, arg2 ...]]) synchronously invokes each function in the list. Handlers run in the order they were added. If a handler returns false and the list was created with the stopOnFalse flag, remaining callbacks are skipped.

fire() does nothing when the list is empty, disabled, or locked in a state that prevents firing. It does not throw — which makes defensive checks with disabled() optional but helpful for logging.

💡
Beginner Tip

Always add() handlers before fire() unless you use the memory flag and plan to fire first — a pattern covered in the $.Callbacks() tutorial.

📝 Syntax

General form of callbacks.fire:

jQuery
callbacks.fire( [ arg1 [, arg2 ... ] ] )

Parameters

  • arg1, arg2, … (optional) — values forwarded to every callback as positional arguments.

Return value

  • Returns the same Callbacks object for chaining.

Classic example

jQuery
const callbacks = $.Callbacks();



callbacks.add(function (message) {

  console.log("Callback 1:", message);

});



callbacks.add(function (message) {

  console.log("Callback 2:", message.toUpperCase());

});



callbacks.fire("Hello, world!");

⚡ Quick Reference

GoalCode
Run all handlerscallbacks.fire()
Pass data to handlerscallbacks.fire(data, extra)
Custom this valuecallbacks.fireWith(ctx, [args])
Register handlerscallbacks.add(fn)
Check if list is offcallbacks.disabled()
Check if ever firedcallbacks.fired()

📋 add() vs fire() vs fireWith()

Registration, invocation, and context control on a Callbacks list.

add()
queue fn

Subscribe — does not run handlers

fire()
run all

Invoke every handler with args

fireWith()
this + args

Set this inside handlers

Order
FIFO

First added runs first

Examples Gallery

Each example shows a different aspect of triggering Callbacks lists.

📚 Getting Started

Pass a message to every registered handler.

Example 1 — Fire With Arguments

Each handler receives the same string argument from fire().

jQuery
const callbacks = $.Callbacks();



callbacks.add(function (message) {

  console.log("Callback 1:", message);

});



callbacks.add(function (message) {

  console.log("Callback 2:", message.toUpperCase());

});



callbacks.fire("Hello, world!");
Try It Yourself

How It Works

Both handlers receive "Hello, world!" as the first parameter. Transform or branch inside each callback as needed.

Example 2 — Handlers Run in Registration Order

fire() walks the queue first-in, first-out.

jQuery
const callbacks = $.Callbacks();



callbacks.add(function () { console.log("Step 1"); });

callbacks.add(function () { console.log("Step 2"); });

callbacks.add(function () { console.log("Step 3"); });



callbacks.fire();
Try It Yourself

How It Works

Order matters for pipelines — validate, transform, then render. Register handlers in the sequence you want them to execute.

📈 Practical Patterns

Edge cases and real-world event triggering.

Example 3 — Fire on an Empty List

No handlers means fire() completes silently — no error thrown.

jQuery
const callbacks = $.Callbacks();



console.log("Handlers before fire:", callbacks ? "list exists" : "missing");

callbacks.fire("data");

console.log("Fire completed — no handlers ran");
Try It Yourself

How It Works

Same behavior after empty() or on a fresh list with no add() calls. Consider logging when zero handlers ran if that indicates a bug.

Example 4 — Multiple fire() Calls

On a default list, each fire() runs every handler again.

jQuery
const callbacks = $.Callbacks();



callbacks.add(function (n) {

  console.log("Count:", n);

});



callbacks.fire(1);

callbacks.fire(2);
Try It Yourself

How It Works

Use $.Callbacks("once") when handlers should run only on the first fire — common for one-time init hooks.

Example 5 — Custom Event Bus

Wrap fire() in a public emit() method for pub/sub style APIs.

jQuery
const EventBus = (function () {

  const onData = $.Callbacks();



  return {

    subscribe: function (fn) { onData.add(fn); },

    emit: function (payload) {

      if (!onData.disabled()) {

        onData.fire(payload);

      }

    }

  };

})();



EventBus.subscribe(function (data) {

  console.log("Received:", data.id, data.value);

});



EventBus.emit({ id: 42, value: "temperature" });
Try It Yourself

How It Works

Plugins often hide the raw Callbacks object and expose on/emit wrappers — emit internally calls fire().

🚀 Use Cases

  • Custom events — trigger subscriber callbacks on user actions or data changes.
  • Plugin lifecycle — fire onInit, onDestroy, or onUpdate hook lists.
  • Async completion — fire when a timer, animation, or mock AJAX step finishes.
  • Pipeline stages — pass shared context objects through ordered handlers.
  • Testing — fire lists in unit tests to verify subscribers react correctly.

🧠 How fire() Works

1

Subscribe

Handlers register with add() and wait in a queue.

add()
2

fire()

jQuery loops the queue, calling each function with your arguments.

Invoke
3

Flags apply

once, stopOnFalse, and memory alter repeat and replay behavior.

Rules
=

Coordinated execution

One trigger, many listeners — the core pub/sub pattern in jQuery.

📝 Notes

  • fire() runs synchronously — long handlers block until they finish.
  • Handlers added during a fire (from inside another handler) may run in the same invocation — behavior depends on list state; avoid unless intentional.
  • After disable(), fire() is always a no-op.
  • Use fireWith(element, [args]) when handlers need this to be a DOM node.
  • fired() tells you whether the list has fired at least once — useful with once lists.

Browser Support

callbacks.fire() is part of jQuery’s Callbacks API since jQuery 1.7 and works wherever jQuery runs.

jQuery 1.7+

jQuery Callbacks.fire()

Supported in jQuery 1.x, 2.x, and 3.x across all browsers with a compatible jQuery build.

100% With jQuery loaded
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
callbacks.fire() Universal

Bottom line: Safe in jQuery projects. Pair with add() for subscribe and fire() for publish.

🎉 Conclusion

The callbacks.fire() method is the trigger that makes Callbacks lists useful — it runs every registered handler with the arguments you provide. Master the add-then-fire workflow, know when to use fireWith(), and respect list flags like once and stopOnFalse.

Next, learn fired() to check whether a list has been invoked, and fireWith() for custom this binding.

💡 Best Practices

✅ Do

  • Register handlers with add() before fire()
  • Pass consistent argument shapes to subscribers
  • Wrap fire() in named emit() methods
  • Check disabled() in shared buses when useful
  • Pick Callbacks flags for once or memory when needed

❌ Don’t

  • Fire before any subscribers register (unless using memory)
  • Run heavy blocking work inside fire handlers without notice
  • Assume fire throws when the list is empty
  • Confuse fire() with fireWith()
  • Fire disabled lists expecting side effects

Key Takeaways

Knowledge Unlocked

Five things to remember about fire()

The publish step in jQuery Callbacks.

5
Core concepts
+ 02

add()

Subscribe first

Queue
1,2,3 03

Order

FIFO

Sequence
📦 04

Args

Shared data

Payload
🔌 05

emit()

Pub/sub pattern

Pattern

❓ Frequently Asked Questions

fire() invokes every handler currently registered on the Callbacks list, in registration order. Optional arguments you pass to fire() are forwarded to each callback function.
Use fire(args...) when the default this value (the Callbacks list in strict mode, or window in sloppy mode) is fine. Use fireWith(context, args) when handlers need a specific this — such as a DOM element or plugin instance.
Nothing runs — fire() completes silently with no errors. This is safe but can hide logic bugs if you expected handlers to exist.
No. disable() permanently shuts down the list. fire() becomes a no-op and disabled() returns true.
Yes, on a default Callbacks list. Each fire() runs all current handlers again. With the once flag on $.Callbacks("once"), only the first fire() has effect.
It returns the same Callbacks object, so you can chain: callbacks.fire(data).add(fn) — though adding after firing is less common than firing after add().
Did you know?

jQuery’s internal naming mirrors this API: fire() runs handlers, and fired() reports whether firing ever happened — the same action/status pairing as disable() / disabled().

Continue to fired()

Learn how to tell whether a Callbacks list has been invoked at least once.

fired() 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.

6 people found this page helpful