jQuery Callbacks disable() Method

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

What Is disable()?

callbacks.disable() permanently shuts down a Callbacks list (since jQuery 1.7). The official API describes it as disabling the list from doing anything more. Afterward, fire() / fireWith() are no-ops. Returns the same Callbacks object for chaining.

Remember
callbacks.add(fn)
callbacks.fire("foo")     // runs
callbacks.disable()
callbacks.fire("foobar")  // ignored — no output

disabled() → true after disable()
no enable() method exists
NeedUse
Stop all future firingcbs.disable()
Check if shut downcbs.disabled()
Freeze add/remove onlycbs.lock()
Clear handlers (still fireable)cbs.empty()

How to Use disable()

Call it when the list must never run again — usually during teardown.

  1. Create and use a Callbacks list normally (add / fire).
  2. When the feature ends (destroy, unmount, fatal error), call disable().
  3. Optionally check disabled() in shared helpers before firing.
  4. Remember: no re-enable — make a new list if you need a fresh bus.
PieceRequired?Role
Callbacks objectYesList to shut down
ArgumentsNonedisable() takes no parameters
Return—Same Callbacks object (chainable)

Pseudocode

Pseudocode
list = Callbacks queue
disabledFlag = false

disable():
  disabledFlag = true
  // list can no longer do anything useful

fire(args…):
  if disabledFlag:
    return          // no-op
  call every handler

disabled():
  return disabledFlag

Cheat Sheet

Keep these facts handy when tearing down Callbacks lists.

TopicDetail
Syntaxcallbacks.disable()
ArgumentsNone
EffectFuture fire() / fireWith() ignored
Reversible?No — permanent
Status checkdisabled() → true
vs lock()Lock freezes membership; fire still works
SincejQuery 1.7

Live Preview

Compare disable timing and lock() side by side on a fresh list.

Browser demo of callbacks.disable — same ideas as the examples below.

Result
add(foo); disable(); fire("x")
→ (no output)
disabled() → true

jQuery Examples

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

Example 1 — Disable Before fire()

Register handlers, call disable(), then try to fire — nothing runs.

jQuery
var callbacks = $.Callbacks();

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

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

callbacks.disable();
callbacks.fire(); // no output
Try It Yourself

How It Works

  1. Register. Two handlers join the list.
  2. Disable. The list is shut down before any fire.
  3. Fire. Invocation is a no-op — nothing prints.
  4. Takeaway. Order matters: disable first means handlers never run.

Example 2 — Disable After a Successful fire()

The first fire() runs; after disable(), later fires are ignored.

jQuery
var callbacks = $.Callbacks();

callbacks.add(function () {
  console.log("Runs once");
});

callbacks.fire();
// → Runs once

callbacks.disable();
callbacks.fire(); // ignored
Try It Yourself

How It Works

  1. First fire. Handler runs normally.
  2. Disable. Marks the list as permanently off.
  3. Second fire. No-op — matches the official docs example.
  4. Use case. Final event, then block stray follow-up fires.

Example 3 — Guard With disabled()

Check status before firing in shared helper code.

jQuery
var callbacks = $.Callbacks();

function safeFire(list) {
  if (list.disabled()) {
    console.log("Skipped — list disabled");
    return;
  }
  list.fire();
}

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

callbacks.disable();
safeFire(callbacks);
// → Skipped — list disabled
Try It Yourself

How It Works

  1. Helper. safeFire reads disabled() first.
  2. Disable the list. Status flips to true.
  3. Call the helper. It logs and returns early.
  4. Why bother? Clearer logs than a silent no-op fire().

Example 4 — disable() vs lock()

lock() still fires; disable() does not.

jQuery
var locked = $.Callbacks();
locked.add(function () { console.log("locked: fired"); });
locked.lock();
locked.fire(); // → locked: fired

var disabled = $.Callbacks();
disabled.add(function () { console.log("disabled: fired"); });
disabled.disable();
disabled.fire(); // no output
Try It Yourself

How It Works

  1. Locked list. Membership freezes, but fire() still runs.
  2. Disabled list. fire() is a no-op.
  3. Choose lock when the handler set is final but you still need to fire.
  4. Choose disable when firing must stop entirely.

Example 5 — Plugin Teardown

Fire a final destroy event, then disable the hook list.

jQuery
var Widget = (function () {
  var onDestroy = $.Callbacks();

  function destroy() {
    onDestroy.fire("destroying");
    onDestroy.disable();
    console.log("Widget torn down, hooks disabled");
  }

  return { onDestroy: onDestroy, destroy: destroy };
})();

Widget.onDestroy.add(function (phase) {
  console.log("Cleanup:", phase);
});

Widget.destroy();
Widget.onDestroy.fire(); // no-op
Try It Yourself

How It Works

  1. Expose a hooks list. Consumers subscribe via onDestroy.add.
  2. Final fire. Cleanup handlers run with "destroying".
  3. Disable. The bus cannot fire again after teardown.
  4. Stray fire. Later fire() calls are silently ignored.

Edge Cases & Pitfalls

Check these before using disable() as teardown.

permanent

No enable()

You cannot undo disable(). Create a new $.Callbacks() list if you need a fresh bus.

silent

Fire becomes a silent no-op

No error is thrown. Use disabled() when you need an explicit log or early return.

lock

Do not confuse with lock()

lock() still allows fire(). Pick the wrong one and handlers keep running after “teardown.”

empty

empty() ≠ disable

empty() clears handlers but the list can still accept new add() / fire() calls.

once

once is not the same

$.Callbacks("once") stops after one fire but is a creation flag. disable() shuts down any list at any time.

Browser Support

callbacks.disable() is part of jQuery’s Callbacks API (since 1.7). It works in any browser where your jQuery build runs — the list logic lives in jQuery, not as a separate browser API.

✓ jQuery 1.7+ · Browsers

jQuery callbacks.disable()

Supported in jQuery 1.x, 2.x, and 3.x across Chrome, Firefox, Safari, Edge, and other browsers with jQuery loaded.

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.disable() Browsers

Bottom line: Safe wherever jQuery is loaded. Call disable() for final teardown; use disabled() to read status.

Performance Notes

OperationCostBest for
disable()O(1)One-time teardown
disabled()O(1)Status checks in helpers
fire() when disabledO(1) early exitSafe stray calls (still prefer a guard for clarity)

disable() is cheap. Call it once at teardown — do not toggle repeatedly (you cannot re-enable anyway). Prefer one disable on destroy over repeatedly checking custom flags in every hot path.

Key Takeaways

  • Role: permanently stop a Callbacks list from doing more work.
  • Status: use disabled() to read the flag.
  • vs lock: lock freezes membership; disable kills firing.
  • Teardown: fire a final event, then disable() so late calls cannot revive the bus.

One line: disable() is the permanent off switch for a Callbacks list.

Frequently Asked Questions

disable() permanently shuts down a Callbacks list. After calling it, fire() and fireWith() become no-ops — they return without invoking handlers. The official description is: disable a callback list from doing anything more.
No. jQuery has no enable() method. disable() is one-way. To fire again, create a fresh $.Callbacks() list or keep your own pause flag outside Callbacks.
lock() freezes the handler set — no more add() or remove() — but fire() still runs existing handlers. disable() stops all future firing. lock() protects the queue; disable() kills it.
Treat disable() as final teardown. Further add() and fire() calls are effectively ignored. Check disabled() when debugging missing handlers.
Call disabled() — it returns true after disable() has run. That is the read-only status check; disable() is the action that turns firing off.
Common cases: plugin destroy/unmount, shutting down an event bus after app teardown, or blocking stray fires after a one-time workflow completes. Pair with disabled() in defensive helpers.

Next: disabled()

Learn how to read whether a Callbacks list has already been shut down.

disabled() 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