jQuery Callbacks remove() Method

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Unregister

What You’ll Learn

The remove() method unregisters specific function references from a jQuery Callbacks list — the counterpart to add(). This tutorial covers syntax, five examples, comparisons with empty(), and unsubscribe patterns for event buses and plugins.

01

Syntax

remove(fn)

02

Reference

Same function object

03

vs add()

Unregister

04

vs empty()

One vs all

05

has()

Check first

06

lock()

Blocks remove

Introduction

You use add() to subscribe handlers to a Callbacks list. When a component unmounts, a user logs out, or a one-time listener is no longer needed, those handlers should come off the list — otherwise the next fire() still invokes them.

remove() is how you unsubscribe. Pass the same function reference you used with add(), and jQuery drops it from the queue.

Understanding the remove() Method

callbacks.remove(callback [, callback]) removes one or more handlers from the list by reference. Removed functions no longer run on subsequent fire() or fireWith() calls. The method returns the same Callbacks object for chaining.

It does not clear the entire list when called with no arguments. The old reference incorrectly stated that omitting the callback removes all handlers — use empty() for that. Matching is by reference, same as has().

💡
Beginner Tip

Keep a named reference to every handler you may unsubscribe later. Anonymous functions added inline cannot be removed unless you stored them in a variable first.

📝 Syntax

General form of callbacks.remove:

jQuery
callbacks.remove( callback [, callback ] )

Parameters

  • callback — One or more function references to remove from the list. Each must match a handler previously added with add().

Return value

  • Returns the same Callbacks object (supports chaining).

Basic pattern

jQuery
const callbacks = $.Callbacks();



function onUpdate() { console.log("Updated"); }



callbacks.add(onUpdate);

callbacks.fire();   // → Updated

callbacks.remove(onUpdate);

callbacks.fire();   // nothing runs

⚡ Quick Reference

GoalCode
Remove one handlercallbacks.remove(fn)
Remove several handlerscallbacks.remove(fn1, fn2)
Clear entire listcallbacks.empty()
Check before removeif (callbacks.has(fn)) callbacks.remove(fn)
Register handlercallbacks.add(fn)

📋 remove() vs add() vs empty()

Unregister specific handlers versus register versus wipe all.

add(fn)
register

Put handler on list

remove(fn)
unregister

Drop specific reference

empty()
clear all

Remove every handler

After lock()
no-op

remove() silently ignored

Examples Gallery

Each example shows a different way to use remove() in real Callbacks workflows.

📚 Getting Started

Drop one handler; the rest still fire.

Example 1 — Remove One Handler

Add two handlers, fire, remove one, then fire again.

jQuery
const callbacks = $.Callbacks();



function foo() { console.log("Foo"); }

function bar() { console.log("Bar"); }



callbacks.add(foo);

callbacks.add(bar);

callbacks.fire();       // Foo, Bar

callbacks.remove(foo);

callbacks.fire();       // Bar only
Try It Yourself

How It Works

Only foo was removed. bar stays registered and runs on the second fire().

Example 2 — Remove Multiple Handlers at Once

Pass several references in a single remove() call.

jQuery
const callbacks = $.Callbacks();



const a = function () { console.log("A"); };

const b = function () { console.log("B"); };

const c = function () { console.log("C"); };



callbacks.add(a, b, c);

callbacks.remove(a, b);

callbacks.fire(); // → C
Try It Yourself

How It Works

Variadic remove(a, b) mirrors variadic add(a, b, c) — drop several handlers in one call.

📈 Practical Patterns

Surgical removal, bulk clear, and API design.

Example 3 — remove() vs empty()

Remove one handler; use empty() when you want zero left.

jQuery
const callbacks = $.Callbacks();



const loggerA = function () { console.log("Logger A"); };

const loggerB = function () { console.log("Logger B"); };



callbacks.add(loggerA, loggerB);

callbacks.remove(loggerA);

callbacks.fire(); // → Logger B



callbacks.empty();

callbacks.fire(); // nothing
Try It Yourself

How It Works

remove() is surgical. empty() wipes the rest — do not call remove() with no args expecting that behavior.

Example 4 — Unsubscribe API With has()

Wrap remove() in a public unsubscribe method for an event bus.

jQuery
const EventBus = (function () {

  const listeners = $.Callbacks();



  return {

    on: function (fn) { listeners.add(fn); },

    off: function (fn) {

      if (listeners.has(fn)) {

        listeners.remove(fn);

        console.log("Unsubscribed");

      }

    },

    emit: function (data) { listeners.fire(data); }

  };

})();



const handler = function (d) { console.log("Got:", d); };

EventBus.on(handler);

EventBus.emit("hello");  // → Got: hello

EventBus.off(handler);

EventBus.emit("again");  // nothing
Try It Yourself

How It Works

Pairing has() with remove() avoids silent no-ops when the handler was never registered.

Example 5 — remove() Blocked After lock()

On a locked list, removal is ignored — the handler still fires.

jQuery
const callbacks = $.Callbacks();

const handler = function () { console.log("Still registered"); };



callbacks.add(handler);

callbacks.lock();

callbacks.remove(handler); // ignored

callbacks.fire();          // → Still registered
Try It Yourself

How It Works

Remove handlers before calling lock(), or check locked() first if your API allows late unsubscription.

🚀 Use Cases

  • Event unsubscriptionoff(fn) wrapping remove(fn).
  • Component teardown — drop handlers when a widget is destroyed.
  • One-time listeners — remove self inside the handler after first fire.
  • Duplicate cleanup — remove extra copies of the same reference.
  • Plugin APIs — let users detach custom hooks they no longer need.

🧠 How remove() Updates the List

1

add() handlers

Functions registered on the Callbacks list.

Register
2

remove(fn)

Matching references dropped by identity lookup.

Unregister
3

fire()

Only remaining handlers run.

Invoke
=

Lean handler set

Stale subscribers no longer run on future events.

📝 Notes

  • Pass the exact function reference — remove() does not match by name or source code.
  • Use empty() to clear all handlers; do not omit args from remove() for that.
  • After lock(), remove() is a no-op.
  • Removing a handler that is not on the list is safe — jQuery ignores it silently.
  • has(fn) returns false immediately after a successful remove(fn).

Browser Support

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

jQuery 1.7+

jQuery Callbacks.remove()

Supported in jQuery 1.x, 2.x, and 3.x. Reference-based removal behaves consistently across browsers.

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.remove() Universal

Bottom line: Safe in jQuery projects. Store references for handlers you plan to remove later.

🎉 Conclusion

The callbacks.remove() method unregisters specific handlers from a Callbacks list by function reference. It pairs with add(), contrasts with empty() for bulk clearing, and respects lock() when the list is frozen.

You have now covered the full jQuery Callbacks API. Next, explore Deferred — which uses Callbacks lists internally for promise-style async workflows.

💡 Best Practices

✅ Do

  • Store named references for handlers you will remove
  • Wrap remove() in off() / unsubscribe() APIs
  • Use has() before remove when membership is uncertain
  • Prefer empty() when dropping every handler
  • Remove hooks during component/plugin teardown

❌ Don’t

  • Expect remove() with no args to clear the list
  • Try to remove anonymous inline functions without a reference
  • Call remove() after lock() expecting success
  • Confuse remove() with disable()
  • Forget to unsubscribe — causes memory leaks and duplicate runs

Key Takeaways

Knowledge Unlocked

Five things to remember about remove()

Unregister handlers from Callbacks lists.

5
Core concepts
🔗 02

Reference

Same object

Match
+ 03

add()

Opposite

Pair
04

empty()

Clear all

Compare
🔒 05

lock()

Blocks remove

Control

❓ Frequently Asked Questions

remove(callback) unregisters one or more function references from a Callbacks list. After removal, those functions no longer run on the next fire(). It does not run callbacks — it only drops them from the queue.
No. Unlike incorrect documentation sometimes found online, remove() requires the callback reference(s) you want to drop. To wipe every handler at once, use empty() instead.
remove(fn) drops specific handlers you pass by reference. empty() clears the entire list in one call — useful when you do not need to name each function.
No. Once lock() freezes the list, remove() becomes a silent no-op — same as add(). Check locked() before attempting removal.
Yes. Pass multiple function references: callbacks.remove(fn1, fn2, fn3). Each matching handler is removed from the list.
Both use reference equality. After remove(fn), has(fn) returns false. Use has() first when you are unsure whether a handler is still registered.
Did you know?

jQuery’s unique flag on $.Callbacks("unique") prevents duplicate references at add() time — but if duplicates slip in without that flag, remove(fn) drops only the first matching entry per call.

Continue to Deferred

Learn promise-style async patterns built on jQuery Callbacks lists.

Deferred 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