jQuery .promise() method
Example
Call .promise() on a collection with no active animations
$
(
function
(
)
{
var
div
= $
(
"
"
)
;
div
.
promise
(
)
.
done
(
function
(
arg1
)
{
//
Alert "true"
alert
(
this
===
div
&&
arg1
===
div
)
;
}
)
;
}
)
Try it »
Definition and Usage
The .promise() function returns a Promise object that observes whether all actions of a certain type bound to a collection have been added to the queue.
**Note:** 1. The .promise() method returns a dynamically generated Promise, which is resolved when all specific actions bound to the collection have finished, whether they were queued or not.
2. The default value of type is "fx", which means the resolved Promise object is returned when the animations of all selected elements have completed.
3. If a target argument is provided, .promise() adds methods to that argument and then returns that object instead of creating a new one. It is suitable for adding Promise behavior to an already existing object.
Syntax
.promise( [type ] [, target ] )
| Parameters | Description |
|---|---|
| type | String type: The type of queue to observe. |
| target | PlainObject type: The object to which the promise methods will be bound. |
More examples
Resolve the returned Promise when the animations end
Resolve the returned Promise when all animations end (including those initialized within animation callbacks and callbacks added afterwards).
Resolve the returned Promise using the $.when() statement
Resolve the returned Promise using the $.when() statement (made possible by the .promise() method on jQuery collections).
jQuery Miscellaneous Methods