jQuery Callbacks add() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Callbacks

Definition

callbacks.add() appends one or more functions to a jQuery Callbacks list (since jQuery 1.7). It queues handlers; they run when you call fire() or fireWith(). Returns the same Callbacks object for chaining.

Syntax

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

jQuery
callbacks.add( fn )
callbacks.add( fn1, fn2 )       // multiple args
callbacks.add( [fn1, fn2] )     // array of functions

add()  → queue (does not run)
fire() → run every handler in order

returns the Callbacks object (chainable)
CallWhat it does
Callbacks objectFrom $.Callbacks()
callback / arrayFunction(s) to append
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: once, memory, unique, stopOnFalse).
Step 2Call add(fn) — or pass several functions / an array.
Step 3Trigger with fire() or fireWith(context, args) when you want handlers to run.

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

Example 1 — Add One Callback and Fire

Create a list, register one handler, then fire.

jQuery
var callbacks = $.Callbacks();

callbacks.add(function () {
  console.log("First callback executed");
});

callbacks.fire();
Try It Yourself

How It Works

  1. Create the list. $.Callbacks() starts with an empty queue.
  2. Register. add() stores the function — nothing prints yet.
  3. Fire. fire() walks the list and calls the handler.

Example 2 — Multiple Handlers (Args or Array)

Pass several functions at once, or wrap them in an array — both append in order.

jQuery
var callbacks = $.Callbacks();

function step1() { console.log("Step 1: validate"); }
function step2() { console.log("Step 2: save"); }
function step3() { console.log("Step 3: notify"); }

callbacks.add(step1, step2);   // multiple args
callbacks.add([step3]);        // array form (official API)

callbacks.fire();
Try It Yourself

How It Works

  1. Define named functions. Easier to remove later with remove(step2).
  2. Multi-arg add. add(step1, step2) appends both in order.
  3. Array add. add([step3]) is the official Array overload.

Example 3 — Add After an Earlier fire()

On a default list, every fire() runs all handlers currently registered — including earlier ones.

jQuery
var callbacks = $.Callbacks();

callbacks.add(function () {
  console.log("First callback");
});

callbacks.fire();
// → First callback

callbacks.add(function () {
  console.log("Second callback");
});

callbacks.fire();
// → First callback
// → Second callback
Try It Yourself

How It Works

  1. First fire. Only the first handler exists → one log line.
  2. Late add. Second handler joins the same list.
  3. Second fire. Both handlers run — the first is not cleared.

Frequently Asked Questions

add() registers one or more functions on a jQuery Callbacks list. Those functions run later when you call fire() or fireWith() on the same list. add() itself does not run the callbacks.
Yes. Pass separate function arguments — callbacks.add(fn1, fn2) — or an array — callbacks.add([fn1, fn2]). Both append handlers in order. The official API accepts a Function or an Array of functions.
Not on a default list. Handlers wait until fire() or fireWith(). With the memory flag, a handler added after the list has already fired runs right away with the last memorized arguments.
By default, duplicates are allowed and each copy runs on fire(). Create the list with $.Callbacks("unique") to reject duplicate references.
After lock(), new add() calls are ignored. After disable(), the list is shut down and further adds and fires are effectively no-ops. Check locked() / disabled() when debugging missing handlers.
jQuery Deferred uses Callbacks lists internally for done, fail, and progress queues (typically with once and memory). Calling .done(fn) is conceptually like add(fn) on that internal list.

Next: callbacks.remove() Method — Unregister Handlers

Unregister specific handlers from a Callbacks list.

callbacks.remove() Method — Unregister Handlers 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.

9 people found this page helpful