YouTip LogoYouTip

Misc Promise

# jQuery .promise() Method [![Image 4: jQuery Misc Methods](#)jQuery Misc Methods](#) ## Example Calling .promise() on a collection with no active animations $(function(){var div = $("
"); div.promise().done(function(arg1){//pop up "true" alert(this === div&&arg1 === div); }); }) [Try it Β»](#) * * * ## Definition and Usage The .promise() function returns a Promise object to observe when all actions of a certain type bound to the collection, whether queued or not, have finished. **Note:** 1. The .promise() method returns a dynamically generated Promise that is resolved when all of the specific actions (action) in the collection have been added to the queue or have not been added to the queue. 2. The default value of type is "fx", which means the resolved Promise object is returned when all animations of the selected elements have completed. 3. If the target parameter is provided, .promise() adds methods to that object and then returns the object, instead of creating a new one. It is useful for adding Promise behavior to an existing object. * * * ## Syntax .promise( [, target ] ) | Parameter | Description | | :--- | :--- | | _type_ | String. The type of queue to observe. | | _target_ | PlainObject. The object to which the promise method will be attached. | * * * ![Image 5: Example](#) ## More Examples (#) Resolve the returned Promise when all animations have finished (including those initialized in animation callbacks and subsequent callbacks). [Resolve the returned Promise using $.when() statement](#) Resolve the returned Promise using the $.when() statement (the .promise() method makes it possible to do this with jQuery collections). * * jQuery Misc Methods](#)
← Angularjs2 TutorialMisc Deferred State β†’