jQuery callbacks.fire() Method — Invoke Handlers

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

What Is fire()?

callbacks.fire(arguments) runs every handler on a jQuery Callbacks list (since jQuery 1.7), in add order, with the arguments you pass. It returns the same Callbacks object for chaining.

Remember
callbacks.add(foo)
callbacks.fire("hello")   // foo("hello")
callbacks.fire("world")   // foo("world") again

add()  → queue handlers
fire() → run them now

returns the Callbacks object (chainable)
NeedUse
Run handlerscbs.fire(args…)
Custom thiscbs.fireWith(ctx, [args])
Register firstcbs.add(fn)
Create the list$.Callbacks([flags])

How to Use fire()

Build a list, add handlers, then fire when the event or step is ready.

  1. Create a list with $.Callbacks() (optional flags such as once).
  2. Register handlers with add(fn).
  3. Call fire(arg1, arg2, …) to run every handler with those args.
  4. Call fire() again anytime (unless the list uses once or was disabled).
PieceRequired?Role
Callbacks objectYesFrom $.Callbacks()
argumentsNoValues forwarded to each handler
Return—Same Callbacks object (chainable)

Pseudocode

Pseudocode
function fire(callbacks, args...):
    if callbacks is disabled: return callbacks
    if once and already fired: return callbacks

    for each handler in callbacks.list (in order):
        handler(args...)
        if stopOnFalse and handler returned false: break

    mark list as fired
    return callbacks

Cheat Sheet

Keep these facts handy when publishing to a Callbacks list.

TopicDetail
Syntaxcallbacks.fire( arguments )
SincejQuery 1.7
OrderSame order as add()
Empty listNo-op (no error)
once flagOnly the first fire() runs
CousinfireWith(context, args)

Live Preview

Fire a small Callbacks list and watch handler output accumulate.

Browser demo of callbacks.fire() — same idea as the examples below.

Result
Ready — pick an action and click Run.

jQuery Examples

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

Example 1 — Fire With Arguments

Official style: add one handler, then fire twice with different values.

jQuery
var foo = function (value) {
  console.log("foo: " + value);
};

var callbacks = $.Callbacks();
callbacks.add(foo);

callbacks.fire("hello");  // foo: hello
callbacks.fire("world");  // foo: world
Try It Yourself

How It Works

  1. Create a Callbacks list with $.Callbacks().
  2. Add foo — it is queued, not run yet.
  3. Fire. Each fire(value) calls foo(value).
  4. Repeat. A default list can be fired many times.

Example 2 — Add Another Handler, Then Fire

Handlers added later join the next fire() pass.

jQuery
var lines = [];
var foo = function (value) { lines.push("foo: " + value); };
var bar = function (value) { lines.push("bar: " + value); };

var callbacks = $.Callbacks();
callbacks.add(foo);
callbacks.add(bar);
callbacks.fire("hello again");

console.log(lines.join("\\n"));
// foo: hello again
// bar: hello again
Try It Yourself

How It Works

  1. Two handlers are registered with add().
  2. One fire runs both, in the order they were added.
  3. Same args are passed to every handler.
  4. Pattern. Publish once; all subscribers receive the payload.

Example 3 — once Flag Blocks Extra Fires

Only the first fire() runs when the list is created with "once".

jQuery
var lines = [];
var cbs = $.Callbacks("once");
cbs.add(function (msg) { lines.push(msg); });

cbs.fire("first");
cbs.fire("second");  // ignored

console.log(lines.join(", "));  // "first"
Try It Yourself

How It Works

  1. Flag. $.Callbacks("once") makes the list one-shot.
  2. First fire runs handlers normally.
  3. Later fires do nothing.
  4. Use case. Init hooks that must not run twice.

Example 4 — Empty List and Disabled List

fire() is safe on empty lists and silent after disable().

jQuery
var empty = $.Callbacks();
empty.fire("noop");  // no handlers — no error

var cbs = $.Callbacks();
cbs.add(function () { console.log("hi"); });
cbs.disable();
cbs.fire("x");       // no-op
console.log(cbs.disabled());  // true
Try It Yourself

How It Works

  1. Empty. Firing with zero handlers does nothing.
  2. Disable. disable() shuts the list down permanently.
  3. Silent. Later fire() calls do not throw.
  4. Check. Use disabled() when debugging missing output.

Edge Cases & Pitfalls

Check these before relying on fire() in plugins.

this

Need a custom this?

Use fireWith(context, args) instead of fire().

once

once ignores later fires

Create the list with $.Callbacks("once") only when a single publish is intended.

stop

stopOnFalse can halt the chain

If a handler returns false and the list uses that flag, later handlers are skipped.

order

Add before fire (usually)

Late add() joins future fires. With memory, a late add can also replay the last arguments immediately.

Browser Support

callbacks.fire() has shipped since jQuery 1.7 with $.Callbacks. It works in all modern browsers with jQuery loaded.

✓ jQuery 1.7+

callbacks.fire()

Core Callbacks publisher — invoke every registered handler with optional arguments.

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
callbacks.fire() Excellent

Bottom line: Call fire(args…) to publish. Use fireWith for a custom this, and remember disable() / once change later fires.

Performance Notes

ApproachCostBest for
fire(args)O(n) handlersPublishing to the full list
add(fn)O(1)*Subscribing handlers
Heavy work inside handlersBlocks the passKeep callbacks light; defer work

*Unless the list uses unique. Prefer lean handlers — one slow callback delays every later subscriber in the same fire().

Key Takeaways

  • Role: fire() publishes — add() subscribes.
  • Args: values passed to fire() reach every handler.
  • Flags: once, memory, and stopOnFalse change fire behavior.
  • Context: use fireWith when handlers need a specific this.

One line: fire(args…) runs every registered handler in order — unless the list is disabled or already spent under once.

Frequently Asked Questions

fire() calls every function currently registered on the Callbacks list, in registration order. Any arguments you pass to fire() are forwarded to each handler. It returns the same Callbacks object for chaining.
Use fire(args…) when you only need to pass arguments. Use fireWith(context, argsArray) when handlers must run with a custom this value (for example a DOM element or plugin object).
fire() completes with no errors and no handlers run. Safe, but easy to miss if you expected subscribers.
No. After disable(), fire() is a no-op. Check disabled() when debugging silent fires.
Yes on a default list — each fire() runs all current handlers again. With $.Callbacks("once"), only the first fire() has effect.
Yes. After a successful fire, fired() returns true. That matters for flags like memory (late add() can replay the last arguments).

Next: fireWith()

Invoke handlers with a custom this context and args array.

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

8 people found this page helpful