jQuery callbacks.fire() Method — Invoke Handlers

Beginner
5 min read
Updated: Nov 2026
3 examples
Callbacks

Definition

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.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
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)
CallWhat it does
Callbacks objectFrom $.Callbacks()
argumentsValues forwarded to each handler
ReturnSame Callbacks object (chainable)

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Create a list with $.Callbacks() (optional flags such as once).
Step 2Register handlers with add(fn).
Step 3Call fire(arg1, arg2, …) to run every handler with those args.

Return Value

Return ValueDescription
BooleanOften true or false depending on the match or state.
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

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

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.

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.

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: callbacks.fireWith() Method — Context and Args

Invoke handlers with a custom this context and args array.

callbacks.fireWith() Method — Context and Args tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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