The .queue() instance method shows, adds to, or replaces the function queue on matched elements. This tutorial covers all three overloads since jQuery 1.2, the default fx effects queue, comparisons with animate callbacks and .dequeue(), the official read/add/replace demos, and five hands-on examples.
01
Read queue
Returns Array
02
Add callback
Append function
03
Replace array
Swap contents
04
fx queue
Default effects
05
next()
Since jQuery 1.4
06
Custom names
Non-fx queues
Fundamentals
Introduction
jQuery attaches one or more queues of functions to each element. In most apps only the default fx effects queue is used. Queues let a sequence of actions run asynchronously without blocking the rest of your script.
When you write $( "#foo" ).slideUp().fadeIn(), the element starts sliding immediately but fading waits on the fx queue until slideUp completes. .queue(), available since jQuery 1.2, lets you inspect that queue, append custom steps, or replace it entirely.
Concept
Understanding the .queue() Method
.queue( [queueName] ) returns an Array of pending functions. .queue( [queueName], callback ) adds a function and returns a jQuery object. .queue( [queueName], newQueue ) replaces the queue with an array and returns jQuery.
The optional queueName defaults to "fx". Custom callbacks added with .queue(fn) must eventually call .dequeue() or invoke the next parameter — otherwise the chain stalls.
💡
Beginner Tip
Think of .queue() as the control panel for a line of waiting functions. Read the line with no arguments, add someone to the back with a callback, or clear the line by passing [].
queueName (optional String) — name of the queue. Defaults to "fx", the standard effects queue.
callback (Function) — function to add to the end of the queue. Receives next since jQuery 1.4 — call next() to dequeue the following item.
newQueue (Array) — array of functions that replaces the current queue contents (e.g. [] to empty).
Return value
Read overload: an Array of pending functions.
Add or replace overload: a jQuery object for chaining.
Official jQuery API description
jQuery
// slideUp then alert — equivalent to slideUp callback
$( "#foo" ).slideUp();
$( "#foo" ).queue(function() {
alert( "Animation complete." );
$( this ).dequeue();
});
// Modern pattern since jQuery 1.4
$( "#test" ).queue(function( next ) {
// Do some stuff...
next();
});
Cheat Sheet
⚡ Quick Reference
Goal
Code
Read pending fx queue length
$el.queue("fx").length
Add custom step after animation
.queue(function(next) { ... next(); })
Empty the fx queue
$el.queue("fx", [])
Resume after custom callback
$(this).dequeue() or next()
Named custom queue
$el.queue("tasks", fn)
Built-in effects auto-enqueue
.slideUp().fadeIn() runs serially on fx
Compare
📋 Queue read vs callback vs array vs animate callback
Four ways to interact with jQuery queues — each overload or pattern serves a different purpose.
queue read
.queue("fx")
Returns Array of pending functions — inspect length or contents without changing the queue
queue callback
.queue(fn)
Appends a function to the end — must call next() or .dequeue() to continue the chain
queue array
.queue("fx", [])
Replaces entire queue with a new Array — pass [] to empty pending items
animate callback
.slideUp(fn)
Runs when that specific animation completes — no manual dequeue needed
Hands-On
Examples Gallery
Each example demonstrates a .queue() overload on real animation chains. Open DevTools or use the Try-it links. Examples 1, 2, and 4 mirror official jQuery API demos.
📚 Getting Started
Official jQuery API demos — read queue length and add queued callbacks mid-chain.
Example 1 — Official Read: Show fx Queue Length
runIt() loops animations on a div while showIt() polls div.queue("fx").length every 100ms and displays the count.
jQuery
var div = $( "div" );
function runIt() {
div
.show( "slow" )
.animate({ left: "+=200" }, 2000 )
.slideToggle( 1000 )
.slideToggle( "fast" )
.animate({ left: "-=200" }, 1500 )
.hide( "slow" )
.show( 1200 )
.slideUp( "normal", runIt );
}
function showIt() {
var n = div.queue( "fx" );
$( "span" ).text( n.length );
setTimeout( showIt, 100 );
}
runIt();
showIt();
The queue length is: 7 (varies as animations enqueue/dequeue)
Count rises when steps are added, falls as each effect completes
How It Works
Calling .queue("fx") with no callback returns the pending function array. Each chained .animate() and .slideToggle() pushes onto fx — the length reflects how many steps still wait to run.
Example 2 — Official Add: Queued addClass / removeClass
Clicking the body chains show, animate, a queued addClass("newcolor"), animate back, a queued removeClass("newcolor"), then slideUp.
Click: div shows, moves right, turns blue, moves back, turns green, slides up
Each .queue() callback calls .dequeue() so later steps are not blocked
How It Works
.queue(fn) inserts a custom step between built-in effects. Without .dequeue() after each class toggle, the following .animate() and .slideUp() would never start.
📈 Practical Patterns
slideUp alert equivalent, emptying the queue, and named custom queues.
Example 3 — slideUp + Queue Alert (Animate Callback Equivalent)
Adding a queued alert after .slideUp() achieves the same result as passing a callback directly to slideUp.
jQuery
// Using .queue() — no callback param on slideUp
$( "#foo" ).slideUp();
$( "#foo" ).queue(function( next ) {
alert( "Animation complete." );
next();
});
// Equivalent direct callback:
// $( "#foo" ).slideUp(function() {
// alert( "Animation complete." );
// });
Element slides up, then alert: "Animation complete."
Same timing as slideUp(callback) — queue runs after slideUp finishes
How It Works
When slideUp has no callback parameter, .queue(fn) is the way to run code after it completes. The queued function receives next — call it to keep the pipeline moving if more steps follow.
Example 4 — Replace Queue with [] (Official Example 2)
Start button runs a long animation chain. Stop button calls .queue("fx", []) plus .stop() to empty pending steps and halt the current effect.
Start: long animation chain begins
Stop: pending queue cleared, current animation halted via .stop()
How It Works
Passing an empty array replaces the fx queue contents — every not-yet-run function is removed. Pair with .stop() to also halt the effect currently playing. .clearQueue() offers a dedicated shortcut for the same pending removal.
Example 5 — Named Custom Queue "tasks"
Queue serial work on a custom name separate from fx, then read the pending length with .queue("tasks").
Custom queue names isolate non-animation work from the default fx pipeline. Read overload returns the array for "tasks" just like "fx". Kick off with .dequeue("tasks") to run the first function.
Applications
🚀 Common Use Cases
Inspect animation backlog — poll .queue("fx").length while effects run to debug timing.
Mid-chain DOM updates — toggle classes or swap text between .animate() steps via .queue(fn).
Post-animation alerts — queue callbacks when the preceding method has no callback parameter.
Cancel pending work — replace the queue with [] or use .clearQueue() before starting fresh.
Named serial tasks — isolate non-fx work on queues like "tasks" or "load".
Plugin integration — let extensions append steps to an element’s animation pipeline safely.
🧠 How .queue() Manages Functions
1
Effects enqueue on fx
.animate(), .slideUp(), etc. push steps onto the default queue.
Enqueue
2
Read, add, or replace
No args returns Array; callback appends; array overload swaps contents.
Control
3
Custom callback runs
Queued function executes; must call next() or .dequeue() to advance.
Signal
4
▶
Chain continues
Next queued step runs until the array is empty or stalled without a signal.
Important
📝 Notes
Available since jQuery 1.2; three overloads with different return types (Array vs jQuery).
Default queue name is "fx" — the standard effects queue.
.slideUp().fadeIn() runs serially because fadeIn waits on the fx queue.
Custom .queue(fn) callbacks must call .dequeue() or next() to continue.
Since jQuery 1.4, queued functions receive a next parameter that auto-dequeues.
.queue("fx", []) empties pending items — pair with .stop() to halt the current effect.
Compatibility
Browser Support
.queue() 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 .queue()
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
.queue()Universal
Bottom line: Learn .queue() alongside .dequeue() and .clearQueue() to build reliable animation and serial-task pipelines in legacy and modern jQuery apps.
Wrap Up
Conclusion
The .queue() method is jQuery’s control panel for per-element function queues. Read pending steps with no callback, append custom work with a function, or replace the entire queue with an array.
The fx queue serializes effects so .slideUp().fadeIn() runs in order. Custom callbacks must signal completion via next() or .dequeue() — otherwise the chain stalls. Pair your knowledge with .dequeue() and .clearQueue() for full queue management.
Call next() or $(this).dequeue() at the end of every custom .queue() callback
Use .queue("fx").length to debug how many effects still wait
Prefer the next parameter pattern in new code since jQuery 1.4
Use named queues to separate effects from non-animation serial work
Pair .queue("fx", []) with .stop() when cancelling mid-animation
❌ Don’t
Forget next() or .dequeue() inside custom queued functions — the chain will stall
Confuse read overload (returns Array) with add overload (returns jQuery)
Assume .queue("fx", []) stops the current animation — use .stop() too
Mix up fx and custom queue names — they are independent pipelines
Re-invent animate callbacks when .slideUp(fn) already fits — use .queue() when no callback param exists
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .queue()
Read, add, or replace function queues on any element.
5
Core concepts
📋01
Three overloads
Read / add / replace
API
🎬02
fx default
Effects queue
Queue
🔗03
next() since 1.4
Auto-dequeue arg
Pattern
⚠04
Signal done
dequeue or next()
Critical
📈05
[] empties
Replace queue
Advanced
❓ Frequently Asked Questions
.queue() shows, adds to, or replaces the function queue on matched elements. With no callback or array it returns an Array of pending functions. With a callback it appends that function to the end. With an array it replaces the entire queue contents.
1) .queue([queueName]) — returns Array of pending functions (default queueName "fx"). 2) .queue([queueName], callback) — adds a function to the end; returns jQuery; callback receives next() since 1.4. 3) .queue([queueName], newQueue) — replaces the queue with an Array (e.g. [] to empty it).
"fx" is jQuery's default effects queue. Methods like .slideUp(), .fadeIn(), and .animate() push steps onto fx and run them one at a time. Chaining $("#foo").slideUp().fadeIn() runs slideUp first; fadeIn waits in the fx queue until slideUp finishes.
When jQuery runs a function you added with .queue(fn), 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 chain stalls and later animations never start.
.queue(fn) adds a standalone step at the end of the queue — useful when the previous method has no callback parameter (e.g. .slideUp() then alert). An animate callback runs when that specific animation completes. Both can run mid-chain, but .queue() works with any chained method.
It replaces the fx queue with an empty array, removing all pending functions that have not yet run. The official jQuery Example 2 pairs this with .stop() on a Stop button to cancel waiting animations. Use .clearQueue() for a dedicated API that does the same for pending items.
Did you know?
jQuery’s official .queue() read demo loops div.queue("fx") every 100ms while runIt() chains show, animate, slideToggle, and slideUp — the displayed length rises and falls as steps enqueue and dequeue. That live counter is one of the few ways to visualize the invisible fx pipeline backing every chained animation.