jQuery .queue() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Utilities

Definition

jQuery.queue(element, …) (alias $.queue) shows or changes the function queue on a DOM element (added in jQuery 1.3). Default queue name is "fx".

Syntax

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

jQuery
// 1) Read (returns Array)
$.queue(element [, queueName])

// 2) Append a function
$.queue(element, queueName, callback)

// 3) Replace the whole queue
$.queue(element, queueName, newQueueArray)

var n = $.queue($("#box")[0], "fx");
console.log(n.length);          // pending steps

$.queue(el, "fx", function () {
  $(this).text("mid");
  $.dequeue(this);              // continue!
});
CallWhat it does
elementRaw DOM element that owns the queue
queueNameDefaults to "fx" when reading
callback / newQueueAppend one function, or replace with an array

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

Parameters

ParameterDescription
Step 1Get a raw DOM node ($el[0] or this in a callback).
Step 2Read with $.queue(el, "fx") and check .length.
Step 3Append with $.queue(el, "fx", fn) — end fn with $.dequeue(this).

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

Example 1 — Official: Show Queue Length

Read the fx queue array and print .length.

jQuery
$("#box").fadeOut(800).fadeIn(800).fadeOut(800);

var n = jQuery.queue($("#box")[0], "fx");
console.log("Queue length is: " + n.length);
Try It Yourself

How It Works

  1. Enqueue. Each fade call adds a step to the fx queue.
  2. Inspect. jQuery.queue(el, "fx") returns the pending array.
  3. Length. n.length is how many steps are still waiting or in flight.

Example 2 — Official: Append a Custom Function

Add a mid-step with $.queue, then continue with $.dequeue.

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

$("#box").fadeOut(400);

jQuery.queue(el, "fx", function () {
  $(this).text("Mid step");
  jQuery.dequeue(this);
});

$("#box").fadeIn(400);
Try It Yourself

How It Works

  1. Start. fadeOut pushes the first fx step.
  2. Append. $.queue(el, "fx", fn) adds your custom work.
  3. Work. Inside fn, update the text (or class).

Example 3 — Official: Replace Queue with []

Drop pending steps by replacing the queue with an empty array.

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

$("#box").fadeOut(2000).fadeIn(2000).fadeOut(2000);

// Later — cancel waiting steps:
jQuery.queue(el, "fx", []);
$("#box").stop();
Try It Yourself

How It Works

  1. Stack up. Several fades fill the fx queue.
  2. Replace. $.queue(el, "fx", []) empties pending functions.
  3. Stop current. .stop() ends the animation already running.

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. Official docs recommend .queue() day to day; jQuery.queue() is the low-level utility.
"fx" is jQuery’s default effects queue. .animate(), .fadeOut(), and similar methods push steps onto fx and run them one at a time. Omitting queueName when reading defaults to fx.
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 step runs.
It replaces the fx queue with an empty array, dropping pending functions that have not started. Pair with .stop() when canceling animations. .clearQueue() is the dedicated instance API for clearing pending items.

Next: jQuery.dequeue() Method

Learn how to run the next function on an element’s queue.

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

9 people found this page helpful