jQuery.queue(element, …) shows or manipulates the function queue on a DOM element. This tutorial covers reading length, appending callbacks, replacing with an array, pairing with jQuery.dequeue(), how it relates to .queue(), five examples, and try-it labs.
01
Read
Queue array
02
Add
Callback
03
Replace
With array
04
Element
Raw DOM node
05
vs .queue()
Prefer instance
06
Since 1.3
Low-level
Fundamentals
Introduction
Every element can hold one or more queues of functions. In most apps you only use fx — the effects queue behind .animate(), .show(), and slides. Queues let steps run in order without blocking the rest of your script.
Since jQuery 1.3, jQuery.queue() is the low-level utility to inspect, append, or replace that list for a single DOM element. Official demos use it to print queue length, insert class toggles mid-chain, and clear pending work with an empty array.
Docs note this is low-level: prefer .queue() on a jQuery collection for day-to-day code. Learn the static form so you can read API samples and work when you already hold a raw node. Pair it with jQuery.dequeue() and the Utilities hub.
Concept
Understanding the jQuery.queue() Method
Always pass a DOM element first (for example $( "div" )[ 0 ]). Then either:
Omit further args (or pass only queueName) to read the queue array.
Pass queueName and a function to append a custom step.
Pass queueName and an array to replace the entire queue.
When you append a function, that step must eventually call jQuery.dequeue(this) (or equivalent) so later animations continue.
💡
Beginner Tip
Think of jQuery.queue(el) as “look at or edit this element’s to-do list.” Prefer $(el).queue(…) in new UI code; use the static form for docs-style samples and raw-node helpers.
Queue length is: N
(N shrinks as each fx step finishes)
How It Works
Reading returns an Array. Its .length is how many functions are still waiting (plus in-flight bookkeeping jQuery keeps on fx). Great for debugging long chains.
Example 2 — Queue a Custom Function
Insert class changes mid-animation with jQuery.queue + jQuery.dequeue.
Box shows, slides right, turns blue, slides back,
removes blue, then slides up
Each custom step calls jQuery.dequeue(this)
How It Works
Appending places your function at the end of the current fx list relative to when you call it. Always dequeue inside those callbacks so the rest of the chain can run.
📈 Practical Patterns
Clearing queues, named queues, and the preferred instance API.
Example 3 — Replace Queue With [] to Stop
Official Stop pattern: empty the queue, then .stop() the running animation.
Pending fx steps removed
Current animation halted with .stop()
Length after clear is typically 0
How It Works
Replacing with [] drops waiting functions. It does not by itself cancel the animation already running — that is why demos also call .stop(). For collections, .clearQueue() is clearer intent.
Example 4 — Custom Queue Name
Build and start a non-fx sequence with jQuery.queue / jQuery.dequeue.
jQuery
var el = document.getElementById( "box" );
jQuery.queue( el, "tasks", function( next ) {
$( el ).text( "Step 1" );
next();
});
jQuery.queue( el, "tasks", function() {
$( el ).text( "Step 2" );
jQuery.dequeue( el, "tasks" );
});
jQuery.dequeue( el, "tasks" ); // start
Both read Array and both can append steps
Prefer .queue() / next() in new projects
jQuery.queue matches many official samples
How It Works
Pick one style per codebase. Static methods shine when documenting utilities or holding a raw element; instance methods chain more naturally with the rest of jQuery.
Applications
🚀 Common Use Cases
Debug long chains — print jQuery.queue(el, "fx").length while effects run.
Insert mid-chain steps — toggle classes between animates (official Example 1).
Stop pending work — replace with [] and call .stop().
Named task queues — sequence non-fx jobs on an element.
Raw DOM helpers — when you already have element, not a jQuery object.
jQuery.queue() has been part of jQuery since 1.3+. It works in every browser supported by your jQuery build — including modern evergreen browsers with jQuery 3.x. Queue behavior is implemented by jQuery, not by a separate browser API.
✓ jQuery 1.3+
jQuery.queue()
Stable low-level queue utility across supported jQuery versions. Prefer .queue() for element collections.
100%With jQuery 1.3+
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
jQuery.queue1.3+
Bottom line: Use to inspect or edit queues; prefer instance .queue() in application code.
Wrap Up
Conclusion
jQuery.queue() shows, extends, or replaces an element’s function queue. It is the low-level twin of .queue() — perfect for understanding official demos, while most new code should use the instance method.
Dequeue (or call next()) inside every custom callback
Use .length when debugging long fx chains
Pair queue(el, "fx", []) with .stop() when aborting
Prefer .queue() in new UI code
❌ Don’t
Pass a jQuery object where an Element is required
Forget dequeue after appending a function
Expect custom queues to auto-start
Clear a queue when you only meant to advance it
Mix up fx with a custom queueName
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about jQuery.queue
The low-level show / add / replace queue utility.
5
Core concepts
[]01
Reads
Array
Inspect
+02
Adds
Callback
Append
↻03
Replace
With []
Clear
!04
Must
Dequeue
Continue
★05
Prefer
.queue()
Instance
❓ Frequently Asked Questions
jQuery.queue() shows or changes the function queue on a DOM element. With only an element (and optional queueName) it returns an Array of pending functions. With a callback it appends that function. With an array it replaces the whole queue. Added in jQuery 1.3. Prefer $(element).queue() for everyday code.
1) jQuery.queue(element [, queueName]) — returns Array (inspect length). 2) jQuery.queue(element, queueName, callback) — adds a function to the end. 3) jQuery.queue(element, queueName, newQueue) — replaces the queue with that Array (use [] to clear pending steps).
Same jobs, different call shape. jQuery.queue(elem, …) takes a raw DOM element first. .queue() is called on a jQuery collection: $(elem).queue(…). Official docs recommend .queue() day to day; jQuery.queue() is the low-level utility.
"fx" is jQuery’s default effects queue. .animate(), .show(), .slideToggle(), and similar methods push steps onto fx and run them one at a time. Omitting queueName (when reading) defaults to fx; when adding or replacing you usually pass "fx" explicitly as the second argument.
A function you append with jQuery.queue(el, "fx", fn) pauses the pipeline until you finish. Call jQuery.dequeue(this) (or $(this).dequeue() / next()) so the next animation runs. Skipping that leaves later steps stuck.
It replaces the fx queue with an empty array, dropping pending functions that have not started. Official demos often pair this with .stop() on a Stop button. .clearQueue() is the dedicated instance API for clearing pending items.
Did you know?
The official “show length of queue” demo keeps a looping animation with .slideUp("normal", runIt) so the queue never stays empty for long — that makes the length button interesting to click while effects are still stacked.