jQuery deferred.promise() Method

Last Updated:

jQuery deferred.promise() Method

The jQuery deferred.promise() method returns a Deferred's Promise object.

This method allows an asynchronous function to prevent other code from interfering with the progress or status of its internal request.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style> div{ width: 100px; height: 100px; background: #f69d3c; margin-top: 10px; line-height: 6; text-align: center; } </style> </head> <body> <h1>jQuery deferred.promise() Method</h1> <button>Animate</button> <div id="point1">div1</div> <div id="point2">div2</div> <script> $(document).ready(function(){ $("button").click(function(){ myAnimation("#point1", "fast"); myAnimation("#point2", "slow"); $("#point1, #point2").promise().done(function() { alert("All animations are completed"); }); }); function myAnimation(elem, speed){ $(elem).animate({width: 150}, speed); $(elem).animate({height: 150}, speed); $(elem).animate({width: 100}, speed); $(elem).animate({height: 100}, speed); } }); </script> </body> </html>

Syntax

deferred.promise(target);

Parameter Values

Value Type Explanation
target Optional Specifies an object onto which the promise methods have to be attached.

Browser Support

Devicedesktopmobile
Browsergoogle chromesafarifirefoxinternet Exploreredgeoperagoogle chromesafarifirefoxedgeoperaandroid webviewsamsung internet
deferred.promise()YesYesYesYesYesYesYesYesYesYesYesYesYes

Share this Page

Meet the Author