jQuery callbacks.locked() Method — Check Lock Status

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

What Is locked()?

callbacks.locked() returns a Boolean: true if lock() has frozen that Callbacks list (since jQuery 1.7). It does not change the list or run handlers.

Remember
callbacks.locked()   // false before lock
callbacks.lock()
callbacks.locked()   // true after

lock()    → freeze state (action)
locked()  → boolean status (question)
NeedUse
Is the list locked?cbs.locked()
Freeze the listcbs.lock()
Is the list disabled?cbs.disabled()
Has it been fired?cbs.fired()

How to Use locked()

Ask before you publish again — after a freeze, new fires are ignored.

  1. Build the list, add() handlers, and fire() as needed.
  2. Call locked() — expect false before any lock.
  3. Call lock() when the state should stop changing.
  4. Call locked() again — expect true from then on.
PieceRequired?Role
Callbacks objectYesFrom $.Callbacks()
ArgumentsNonelocked() takes no parameters
Return—Boolean — has lock() run?

Pseudocode

Pseudocode
function locked(callbacks):
    return callbacks.hasBeenLocked

// After lock():
//   hasBeenLocked = true
// There is no unlock() — stays true for this object

Cheat Sheet

Read-only lock status — pair with lock() for the action.

TopicDetail
Syntaxcallbacks.locked()
SincejQuery 1.7
ReturnsBoolean
Changes list?No — status only
Action cousinlock()
Related statusdisabled() / fired()

Live Preview

Fire, lock, and watch locked() flip while later fires stay quiet.

Browser demo of callbacks.locked() — 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 — true After lock()

Official style: lock the list, then call locked().

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

var callbacks = $.Callbacks();
callbacks.add(foo);
callbacks.fire("hello");
// foo: hello

callbacks.lock();
console.log(callbacks.locked());  // true
Try It Yourself

How It Works

  1. Add and fire so the list is active.
  2. lock() freezes the current state.
  3. locked() reports true.
  4. No args. You never pass anything to locked().

Example 2 — false Before Any Lock

A fresh list is not locked until you call lock().

jQuery
var cbs = $.Callbacks();
cbs.add(function () { /* ... */ });
cbs.fire("x");

console.log(cbs.locked());  // false

cbs.lock();
console.log(cbs.locked());  // true
Try It Yourself

How It Works

  1. Fire does not set the locked flag.
  2. Before lock. locked() is false.
  3. After lock. The same call returns true.
  4. Stay true. There is no unlock for this object.

Example 3 — locked() vs disabled()

Different flags answer different questions.

jQuery
var cbs = $.Callbacks("memory");
cbs.add(function (v) { console.log(v); });
cbs.fire("ok");
cbs.lock();

console.log(cbs.locked());    // true
console.log(cbs.disabled());  // false (memory list still usable for late adds)
Try It Yourself

How It Works

  1. lock on a memory list freezes new fire values.
  2. locked() is true.
  3. disabled() can still be false — not the same flag.
  4. Check the right one for the question you mean.

Example 4 — Guard Before fire()

Skip publishing when the list is already locked.

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

function publish(msg) {
  if (cbs.locked()) {
    lines.push("skipped:" + msg);
    return;
  }
  cbs.fire(msg);
}

publish("hello");
cbs.lock();
publish("world");
console.log(lines.join("\n"));
// hello
// skipped:world
Try It Yourself

How It Works

  1. publish checks locked() first.
  2. First call fires normally.
  3. After lock, the guard skips the second fire.
  4. Use case. Clearer logs than a silent no-op fire.

Edge Cases & Pitfalls

Most mix-ups confuse the status check with the freeze action.

action

locked() does not lock

Calling locked() never freezes the list. Use lock() for that.

disabled

Not the same as disabled()

Locked and disabled are separate flags. Check the one that matches your teardown path.

unlock

No unlock API

Once locked() is true, it stays true. Need a reset? Create a new $.Callbacks().

fire

Fire does not set locked

fire() / fireWith() affect fired(), not locked().

Browser Support

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

✓ jQuery 1.7+

callbacks.locked()

Return true if lock() has frozen the Callbacks list.

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

Bottom line: Call locked() to read status. Call lock() when you want to freeze the list.

Performance Notes

ApproachCostBest for
locked()O(1)Status guards
lock() then checkO(1)Finalize + assert
Own boolean flagO(1)Only if you avoid Callbacks

Prefer locked() over a parallel custom flag when you already use $.Callbacks — one source of truth.

Key Takeaways

  • Role: boolean — has lock() run?
  • Read-only: does not freeze or fire.
  • vs disabled: different flag, different meaning.
  • Sticky: no unlock — stays true.

One line: locked() asks “did lock() already freeze this list?”

Frequently Asked Questions

locked() returns true if lock() has been called on the Callbacks list; otherwise false. It is a status check only — it does not lock the list or invoke handlers.
No. locked() accepts no arguments. Flags such as memory belong on $.Callbacks("…") when you create the list.
lock() is the action that freezes the list. locked() answers whether that action has happened. It returns a boolean and does not change the list.
locked() tracks whether lock() froze the list. disabled() tracks whether disable() shut it down. A list can be locked without being disabled (especially with the memory flag).
No. There is no unlock() API. Once locked() is true, it stays true for that Callbacks object. Create a new $.Callbacks() list if you need a fresh unlockable list.
Guard publish helpers so you do not fire after a freeze, assert teardown order in tests, or branch UI/plugin logic that depends on a finalized Callbacks state.

Next: jQuery.Callbacks()

Create Callbacks lists with flags like once, memory, and unique.

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

7 people found this page helpful