jQuery Deferred .promise() method Last Updated : 31 Jul, 2024 Comments Improve Suggest changes Like Article Like Report This .promise() method in JQuery Returns a Promise object to be observed when certain type actions bounded to the collection, queued or not, are ended.Syntax:.promise([type][, target])Parameters:type: This parameter specifies the type of queue which needed to be observed. target: This parameter specifies Object onto which the promise methods need to be attached. Return Value: This method returns a dynamically generated Promise which is resolved once actions bounded to the collection, queued or not, have finished. There are two examples discussed below:Example: In this example, the Deferred() is used to create a new object and after that then() method is called with notify and resolve method. HTML <!DOCTYPE HTML> <html> <head> <title> JQuery.when() method </title> <script src="https://code.jquery.com/jquery-3.5.0.js"> </script> </head> <body style="text-align:center;"> <h1 style="color:green"> GeeksForGeeks </h1> <p id="GFG_UP"> </p> <button onclick="Geeks();"> click here </button> <p id="GFG_DOWN"> </p> <script> var el_up = document.getElementById("GFG_UP"); el_up.innerHTML = "JQuery.when() method"; var def = $.Deferred(); function Geeks() { $.when().then(function (a) { alert("when() method called this alert()."); }); } </script> </body> </html> Output: Example 2: In this example, the Deferred() method is used and the state of Deferred object is checked. HTML <!DOCTYPE HTML> <html> <head> <title> JQuery.when() method </title> <script src="https://code.jquery.com/jquery-3.5.0.js"> </script> </head> <body style="text-align:center;"> <h1 style="color:green"> GeeksForGeeks </h1> <p id="GFG_UP"> </p> <button onclick="Geeks();"> click here </button> <p id="GFG_DOWN"> </p> <script> var el_up = document.getElementById("GFG_UP"); el_up.innerHTML = "JQuery.when() method"; var def = $.Deferred(); function Geeks() { $.when(def).done(function (x) { $('#GFG_DOWN').append('when() method is executed.') }); def.resolve(); } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article jQuery Deferred .promise() method P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JQuery jQuery-Methods Similar Reads JQuery deferred.pipe() Method The deferred.pipe() method in jQuery is used to add utility method to filter, chain Deferreds.Syntax:deferred.pipe([doneFilter][, failFilter][, progressFilter])Parameters: This method accepts three parameter as mentioned above and described below:doneFilter: It is an optional function which is calle 2 min read jQuery deferred.progress() Method This deferred.progress() method in jQuery is used to add handlers which are to be called when the Deferred object generates progress notifications.Syntax:deferred.progress(progressCallbacks[, progressCallbacks])Parameters:progressCallbacks: This parameters is a function, or array of functions, which 2 min read JQuery deferred.resolve() method This deferred.resolve() method in JQuery is used to resolve a Deferred object and call any doneCallbacks with the given arguments. Syntaxdeferred.resolve([args])Parametersargs: This is optional parameters and is arguments which are passed to the doneCallbacks. Return ValueThis method returns the def 2 min read JQuery deferred.state() method This deferred.state() method in JQuery is used to determine the current state of a Deferred object. Syntax: deferred.state()Return Value: This method returns the state of deferred object. There are two examples discussed below: Example: In this example, the state of deferred object 'def' is pending. 2 min read JQuery .Deferred() method This JQuery.Deferred() method in JQuery is a function which returns the utility object with methods which can register multiple callbacks to queues. It calls the callback queues, and relay the success or failure state of any synchronous or asynchronous function.Syntax:jQuery.Deferred([beforeStart])P 2 min read Like