jQuery .queue() Method

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Queue utility

What You’ll Learn

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

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.

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.

📝 Syntax

Three signatures (jQuery 1.3+):

jQuery
jQuery.queue( element [, queueName ] )
jQuery.queue( element, queueName, newQueue )
jQuery.queue( element, queueName, callback )

Parameters

  • element (Element) — DOM node whose queue to read or change.
  • queueName (String) — queue to use. Defaults to "fx" when reading; pass it explicitly when adding or replacing.
  • newQueue (Array) — replaces the current queue contents (often [] to clear).
  • callback (Function) — function appended to the end of the queue.

Return value

  • Array — the queue of functions (when reading, and typically after manipulate forms in the API).

Read length (official pattern)

jQuery
var n = jQuery.queue( $( "div" )[ 0 ], "fx" );
$( "span" ).text( "Queue length is: " + n.length );

⚡ Quick Reference

GoalCode
Read fx queuejQuery.queue( elem, "fx" )
Show lengthjQuery.queue( elem, "fx" ).length
Append a stepjQuery.queue( elem, "fx", fn )
Clear pendingjQuery.queue( elem, "fx", [] )
Preferred instance API$( elem ).queue( … )
Default queue
fx

Effects / animate pipeline

Argument
Element

Raw DOM node, not $()

Read returns
Array

Pending functions on that queue

Prefer
.queue()

Instance method for most apps

📋 jQuery.queue() vs .queue() vs jQuery.dequeue()

jQuery.queue(el, …)$(el).queue(…)jQuery.dequeue(el)
RoleShow / add / replaceSame, on a collectionRun next step
InputDOM elementjQuery objectDOM element
Best forLow-level / docsEveryday chainingFinish a custom step

Examples Gallery

Examples follow the official jQuery API demos. Use View Output or Try It Yourself to explore each case.

📚 Getting Started

Inspect and append — the two most common static uses.

Example 1 — Show Queue Length

While a long animation chain runs, read jQuery.queue(el, "fx").length.

jQuery
$( "#show" ).on( "click", function() {
  var n = jQuery.queue( $( "div" )[ 0 ], "fx" );
  $( "span" ).text( "Queue length is: " + n.length );
});
Try It Yourself

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.

jQuery
var divs = $( "div" )
  .show( "slow" )
  .animate({ left: "+=200" }, 2000 );

jQuery.queue( divs[ 0 ], "fx", function() {
  $( this ).addClass( "newcolor" );
  jQuery.dequeue( this );
});

divs.animate({ left: "-=200" }, 500 );

jQuery.queue( divs[ 0 ], "fx", function() {
  $( this ).removeClass( "newcolor" );
  jQuery.dequeue( this );
});

divs.slideUp();
Try It Yourself

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.

jQuery
$( "#stop" ).on( "click", function() {
  jQuery.queue( $( "div" )[ 0 ], "fx", [] );
  $( "div" ).stop();
});
Try It Yourself

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
Try It Yourself

How It Works

Named queues stay off the effects pipeline. Use the same queueName for queue and dequeue. The first dequeue kicks off the run.

Example 5 — jQuery.queue vs .queue()

Equivalent read and append forms.

jQuery
var el = $( "#box" )[ 0 ];

// Static utility (this tutorial)
var pending = jQuery.queue( el, "fx" );
jQuery.queue( el, "fx", function() {
  $( this ).text( "via jQuery.queue" );
  jQuery.dequeue( this );
});

// Preferred instance method
pending = $( el ).queue( "fx" );
$( el ).queue( "fx", function( next ) {
  $( this ).text( "via .queue()" );
  next();
});
Try It Yourself

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.

🚀 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.
  • Learning effects — bridge to .queue() and jQuery.dequeue().

🧠 How jQuery.queue Fits

1

Effects fill the queue

.animate() and friends push steps onto fx.

Fill
2

Read, add, or replace

jQuery.queue(el, …) inspects or edits that list.

Edit
3

Custom steps dequeue

Appended functions must call jQuery.dequeue (or next).

Continue
4

Pipeline drains

Steps run in order until the queue is empty.

📝 Notes

  • Added in jQuery 1.3; still available in modern jQuery 3.x.
  • Official guidance: prefer .queue() over the static utility.
  • First argument must be a DOM element.
  • Default queue name is "fx".
  • Callbacks you add must eventually dequeue (or call next()).
  • Reading returns an Array — use .length to inspect size.
  • jQuery.queue(el, "fx", []) clears pending items; pair with .stop() to halt the current effect.
  • Related: .clearQueue(), .delay(), .dequeue().

Browser Support

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 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
jQuery.queue 1.3+

Bottom line: Use to inspect or edit queues; prefer instance .queue() in application code.

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.

Next up: jQuery.dequeue() to advance the next queued function.

💡 Best Practices

✅ Do

  • Pass a real DOM element to jQuery.queue
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about jQuery.queue

The low-level show / add / replace queue utility.

5
Core concepts
+ 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.

Next: jQuery.dequeue() Method

Execute the next function waiting on an element’s queue.

jQuery.dequeue() 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.

8 people found this page helpful