jQuery callbacks.locked() Method — Check Lock Status

Beginner
5 min read
Updated: Nov 2026
3 examples
Callbacks

Definition

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.

Syntax

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

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

lock()    → freeze state (action)
locked()  → boolean status (question)
CallWhat it does
Callbacks objectFrom $.Callbacks()
Argumentslocked() takes no parameters
ReturnBoolean — has lock() run?

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

Parameters

ParameterDescription
Step 1Build the list, add() handlers, and fire() as needed.
Step 2Call locked() — expect false before any lock.
Step 3Call lock() when the state should stop changing.

Return Value

Return ValueDescription
BooleanOften true or false depending on the match or state.

jQuery Examples

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.

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.

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.

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: $.Callbacks() Method — Create Callback Lists

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

$.Callbacks() Method — Create Callback Lists 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.

7 people found this page helpful