The .dequeue() instance method removes the next function from a jQuery queue and runs it immediately. This tutorial covers syntax, the default fx effects queue, comparisons with next(), .clearQueue(), and automatic fx advancement, the official animate + toggleClass demo, stalled-queue debugging, named custom queues, and five hands-on examples.
01
Syntax
.dequeue(name)
02
Run next
One queue step
03
fx queue
Default effects
04
Chainable
Returns jQuery
05
vs next()
Same goal
06
Custom queues
Any queue name
Fundamentals
Introduction
jQuery chains animations and callbacks on a per-element queue. When you call .animate() or .queue(fn), steps land on the default fx effects queue and run one at a time. Built-in effects auto-advance when each step finishes.
.dequeue(), available since jQuery 1.2, manually executes the next queued function — it removes that function from the array and runs it. Custom callbacks added with .queue() must call .dequeue() or invoke the next parameter so later steps are not left waiting forever.
Concept
Understanding the .dequeue() Method
.dequeue( [queueName] ) is an instance method on jQuery collections. It accepts an optional String queue name (default "fx") and returns a jQuery object.
It does not run every pending item — only the next one. To drop all waiting functions without executing them, use .clearQueue() instead.
💡
Beginner Tip
Think of the queue as a line. .dequeue() lets the next person through the door. Inside a custom .queue() callback, you are that person — you must open the door for whoever is behind you.
Foundation
📝 Syntax
General form of .dequeue:
jQuery
jQuery( selector ).dequeue( [queueName] )
Parameters
queueName (optional String) — name of the queue to advance. Defaults to "fx", the standard effects queue.
Return value
A jQuery object — the same collection, so you can chain further methods.
Official jQuery API description
jQuery
// Inside a custom queued callback — resume the fx pipeline
$("div").queue(function() {
$(this).toggleClass("red").dequeue();
});
// Advance a named custom queue
$el.dequeue("tasks");
Cheat Sheet
⚡ Quick Reference
Goal
Code
Resume fx after custom callback
$(this).dequeue()
Modern resume pattern
.queue(function(next) { ... next(); })
Advance a named custom queue
$el.dequeue("tasks")
Inspect queue before advancing
$el.queue("fx").length
Drop all pending (don’t run)
$el.clearQueue()
Built-in effects auto-advance
.animate() chains without manual dequeue
Compare
📋 .dequeue vs next() vs .clearQueue vs automatic fx
Four ways jQuery queue pipelines move forward or stop — each plays a different role.
dequeue
run next
Removes and executes the next queued function — one step at a time
next()
callback arg
Modern equivalent inside .queue(fn) — call next() to continue
clearQueue
drop pending
Removes all not-yet-run items without executing any of them
automatic fx
auto step
.animate() and built-in effects dequeue themselves when done
Hands-On
Examples Gallery
Each example demonstrates .dequeue() on real animation chains. Open DevTools or use the Try-it links. Example 1 mirrors the official jQuery API button demo.
📚 Getting Started
Official animation chain with a queued class toggle from the jQuery API.
Example 1 — Official Animate + toggleClass Demo
Button click chains two .animate() calls, a queued .toggleClass("red") that calls .dequeue(), then a final animate back to the start position.
Click: div moves right, moves top, toggles red class, animates back
Full chain completes because .dequeue() resumes after toggleClass
How It Works
Each .animate() auto-advances when its duration ends. The custom .queue() callback pauses the pipeline until .dequeue() runs — then the final .animate() starts.
📈 Practical Patterns
Stalled queues, modern next(), named queues, and serial task logging.
Example 2 — Stalled Queue Without .dequeue()
Forget .dequeue() inside a custom callback and the animation chain stops mid-way. A Fix button adds the missing call to resume.
Broken: box moves right, gets highlight, stops — never returns
Fix: full round-trip animation completes after .dequeue()
How It Works
jQuery treats a custom .queue() function as a gate. Without .dequeue() or next(), the gate stays closed and every step chained after it waits indefinitely.
Example 3 — Modern next() Parameter Pattern
jQuery passes a next callback to queued functions. Calling next() is equivalent to $(this).dequeue() — the preferred style in newer code.
Panel fades in, text updates to "Loaded!", fades out
next() advances the queue — same effect as .dequeue()
How It Works
Under the hood, next() removes the current function and dequeues the following step. Use whichever style reads clearer — both prevent the stalled-queue bug from Example 2.
Example 4 — Dequeue a Named Custom Queue
Queues are not limited to fx. Pass a queue name to .dequeue("tasks") when advancing serial work added with .queue("tasks", fn).
jQuery
var $el = $( "#worker" );
$el.queue( "tasks", function() {
console.log( "task A queued" );
$el.dequeue( "tasks" );
});
$el.queue( "tasks", function() {
console.log( "task B queued" );
$el.dequeue( "tasks" );
});
// Kick off the tasks queue — runs task A, then task B
$el.dequeue( "tasks" );
The initial .dequeue() starts the chain. Each callback finishes its work, then dequeues the next function. Omit any .dequeue() and steps after that callback never run.
Applications
🚀 Common Use Cases
Mid-animation DOM updates — toggle classes, swap text, or measure layout between .animate() steps.
Custom fx callbacks — resume the pipeline after non-animation work in a .queue() function.
Named serial tasks — advance a tasks queue independently of effects.
Plugin hooks — let third-party code inject steps into an animation chain safely.
Async handoff — call .dequeue() or next() after a timeout or AJAX callback completes.
Debugging stalled chains — verify every custom queued function signals completion.
🧠 How .dequeue() Advances a Queue
1
Functions wait in queue
.animate(), .queue(fn), etc. push callbacks onto the array.
Enqueue
2
Current step runs
Built-in effects auto-finish; custom callbacks pause until signaled.
Active
3
Call .dequeue() or next()
Next function is shifted off the array and executed immediately.
Advance
4
▶
Return jQuery
Chain continues until the queue is empty or stalls without a signal.
Important
📝 Notes
Available since jQuery 1.2; returns the jQuery collection (chainable).
Default queue name is "fx" — the standard effects queue.
Removes the next function from the queue, then runs it — one step per call.
Custom .queue() callbacks must call .dequeue() or next() to continue.
Built-in effects like .animate() auto-dequeue — manual calls are for custom callbacks.
Use .clearQueue() to drop pending items without executing them.
Compatibility
Browser Support
.dequeue() is a jQuery instance method since 1.2+. It relies on jQuery’s internal queue system, not on browser-specific APIs — behavior is consistent wherever jQuery runs.
✓ Stable · jQuery 1.2+
jQuery .dequeue()
Supported in all jQuery 1.x, 2.x, 3.x, and 4.x releases. Works in Chrome, Firefox, Safari, Edge, IE 6+ (with compatible jQuery builds), and Node.js via jsdom.
100%jQuery queue API support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.dequeue()Universal
Bottom line: Learn .dequeue() alongside .queue() and .clearQueue() to build reliable animation and serial-task pipelines in legacy and modern jQuery apps.
Wrap Up
Conclusion
The .dequeue() method executes the next function on a jQuery queue — it removes that function and runs it. Built-in effects advance automatically; custom .queue() callbacks need an explicit .dequeue() or next() call.
Forgetting that signal is the most common queue bug: animations appear to freeze mid-chain. Pair your knowledge of .dequeue() with .clearQueue() when you need to cancel pending work instead of advancing it.
Call next() or $(this).dequeue() at the end of every custom .queue() callback
Prefer the next parameter pattern in new code for clarity
Pass a queue name when advancing custom serial task queues
Inspect .queue("fx").length while debugging stalled chains
Use named queues to separate effects from non-animation work
❌ Don’t
Forget .dequeue() inside custom queued functions — the chain will stall
Confuse .dequeue() with .clearQueue() — dequeue runs the next item
Call .dequeue() manually after every .animate() — built-ins auto-advance
Assume next() and .dequeue() differ in behavior — they continue the same queue
Dequeue from the wrong queue name — fx and tasks are independent
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .dequeue()
Advance the queue one step at a time.
5
Core concepts
▶01
dequeue
Run next step
API
📚02
fx default
Effects queue
Queue
🔗03
Chainable
Returns jQuery
Return
⚠04
Signal done
dequeue or next()
Pattern
📈05
Custom names
Non-fx queues
Advanced
❓ Frequently Asked Questions
.dequeue() removes the next function from the specified queue and executes it immediately. It advances the queue by one step — unlike .clearQueue(), which drops all pending items without running them.
An optional string naming which queue to advance. It defaults to "fx" — jQuery's standard effects queue used by .animate(), .show(), and similar methods. Pass a custom name like "tasks" to dequeue from queues created with .queue("tasks", fn).
When jQuery runs a function you added with .queue(), it pauses the pipeline until you signal completion. Calling $(this).dequeue() or the next() argument tells jQuery to run the following queued step. Without that signal, the queue stalls and later animations never start.
They achieve the same goal — continuing the queue. next() is the modern pattern: .queue(function(next) { ... next(); }). .dequeue() is the classic style: .queue(function() { $(this).dequeue(); }). Both remove the current function and start the next one.
Yes for standard effects. jQuery automatically dequeues after each .animate(), .fadeIn(), and similar fx step completes. You only need manual .dequeue() (or next()) inside custom functions added with .queue(fn) — those callbacks do not auto-advance.
A jQuery object — the same collection you called it on. You can chain further methods after .dequeue(), though it is most commonly called inside a queued callback to resume the pipeline.
Did you know?
jQuery’s official .dequeue() demo chains two .animate() calls around a queued .toggleClass("red") — the class flip runs mid-animation only because the callback calls .dequeue(). Without that line, the div would stop after toggling red and never animate back to its start position, even though more methods are chained after the .queue() call.