jQuery .promise() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Effects

Definition

.promise([type][, target]) (since jQuery 1.6) returns a Promise that resolves when all actions of a given type bound to the collection — queued or not — have finished. The default type is "fx", the effects queue used by .animate(), .fadeIn(), .slideUp(), and friends.

This is the collection method $(selector).promise(). It is not deferred.promise(), which returns a read-only view of a Deferred you created yourself. Attach .done() (or .then()) to run code after animations end, or pass the promise to $.when() to combine it with other async work.

Syntax

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

jQuery
$el.promise();                 // default queue: "fx"
$el.promise("fx");             // same, explicit
$el.promise("tasks");          // custom named queue
$el.promise("fx", myObject);   // attach promise methods to myObject

// Typical use
$el.fadeOut(400).fadeIn(400);
$el.promise().done(function () {
  // runs after BOTH effects finish
});
CallWhat it does
.promise()Returns a Promise for the "fx" queue. Already resolved when nothing is animating.
.promise("name")Observes a custom queue instead of "fx".
.promise(type, target)Adds promise methods to target and returns target.

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

Parameters

ParameterDescription
typeOptional string. The queue type to observe. Default is "fx".
targetOptional object. If provided, promise methods are attached to it and it is returned instead of a new promise.

Return Value

Return ValueDescription
PromiseA read-only promise with .done(), .fail(), .then(), .always(), and .state(). Resolves when matching animations on the whole collection finish.
targetWhen a target object is passed, that object is returned with the promise methods added.

jQuery Examples

Example 1 — Immediate Resolved Promise

When nothing is animating, .promise() returns a promise that is already resolved, so .done() runs right away.

jQuery
$("#check").on("click", function () {
  var $box = $("#idle");
  var p = $box.promise();

  $("#status").text("state before done: " + p.state());

  p.done(function () {
    $("#status").append("
done() ran immediately"); }); });
Try It Yourself

How It Works

  1. No effects. #idle has nothing on the fx queue.
  2. Resolved. .promise().state() is already "resolved".
  3. Immediate. .done() fires without waiting.

Example 2 — Wait for fadeIn / fadeOut

Chain a fade out and fade in on a set of items, then run code once the whole set has finished.

jQuery
$("#start").on("click", function () {
  var $items = $(".item");

  $("#status").text("Animating…");
  $items.fadeOut(800).fadeIn(800);

  $items.promise().done(function () {
    $("#status").text("All items finished fading.");
  });
});
Try It Yourself

How It Works

  1. Queue. fadeOut(800).fadeIn(800) puts two steps on fx.
  2. Observe. .promise() watches every element in .item.
  3. Once. .done() runs one time, after the whole set completes.

Example 3 — Use with $.when()

Wrap an effect in a function that returns .promise(), then pass it to $.when().

jQuery
function effect() {
  return $("#box").fadeIn(600).fadeOut(600).promise();
}

$("#run").on("click", function () {
  $("#status").text("Running effect…");

  $.when(effect()).done(function () {
    $("#status").text("$.when(): effect finished.");
  });
});
Try It Yourself

How It Works

  1. Return. effect() returns the collection’s promise.
  2. Combine. $.when() resolves when all passed promises resolve.
  3. Extend. Add more promises (such as $.ajax()) to wait for them together.

Frequently Asked Questions

.promise() returns a Promise that is resolved once every action of a given type bound to the matched collection — queued or not — has finished. By default it watches the "fx" effects queue, so it is the standard way to run code after fadeIn(), slideUp(), animate(), and similar effects complete.
$(selector).promise() is a collection method that observes animations on elements. deferred.promise() is a method of a Deferred object that returns a read-only view of that Deferred so outside code cannot resolve or reject it. They share the word "promise" but solve different problems.
The returned Promise is already resolved, so .done() callbacks run immediately (synchronously). This makes .promise() safe to use even when you are not sure whether an animation was queued.
type is the queue name to observe and defaults to "fx". target is an optional object; when supplied, the promise methods (done, fail, then, and so on) are attached to it and it is returned instead of a new promise object.
Yes. Return $el.promise() from a function and pass the result to $.when(). The combined promise resolves when all passed promises resolve, so you can wait for several effects — or an effect plus an Ajax request — before continuing.
The promise is tied to a Deferred stored in the element’s .data(). .remove() deletes that data along with the element, so any unresolved promise will never resolve. If you must take the element out of the DOM early, use .detach() and call .removeData() after the promise resolves.

Next: Ajax Methods

Load data without a full page refresh — $.ajax, $.get, $.post, and more.

Ajax Methods 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.

10 people found this page helpful