.promise( [type ] [, target ] )Returns: Promise
Description: Return a Promise object to observe when all actions of a certain type bound to the collection, queued or not, have finished.
-
version added: 1.6.promise( [type ] [, target ] )
-
type (default:
fx
)Type: StringThe type of queue that needs to be observed. -
targetType: PlainObjectObject onto which the promise methods have to be attached
-
.promise()
method returns a dynamically generated Promise that is resolved once all actions of a certain type bound to the collection, queued or not, have ended.
type
is "fx"
, which means the returned Promise is resolved when all animations of the selected elements have completed.
.promise()
has been called.
target
is provided, .promise()
will attach the methods onto it and then return this object rather than create a new one. This can be useful to attach the Promise behavior to an object that already exists.
.data()
for an element. Since the.remove()
method removes the element's data as well as the element itself, it will prevent any of the element's unresolved Promises from resolving. If it is necessary to remove an element from the DOM before its Promise is resolved, use .detach()
instead and follow with .removeData()
after resolution.
Examples:
Example 1
.promise()
on a collection with no active animation returns a resolved Promise:
1
2
3
4
5
6
|
|
Example 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
|
Demo:
Example 3
$.when()
statement (the .promise()
method makes it possible to do this with jQuery collections):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
|