JQuery when() method Last Updated : 31 Jul, 2024 Comments Improve Suggest changes Like Article Like Report This JQuery.when() method in JQuery gives a way to execute callback functions depending on zero or more Thenable objects, which usually are Deferred objects that represent asynchronous events.Syntax:jQuery.when(deferreds)Parameters:deferreds: This parameter specifies zero or more Thenable objects.Return Value: This method returns a Promise.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> <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> JQuery.when() method </p> <button onclick = "Geeks();"> click here </button> <p id="GFG_DOWN"> </p> <script> var def = $.Deferred(); function Geeks() { $.when().then(function(a) { alert( "when() method called this alert()." ); }); } </script> </body> </html> Output:Before clicking on button:After clicking on button:Example: In this example, the Deferred() method is used and the state of Deferred object is checked. html <!DOCTYPE HTML> <html> <head> <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> JQuery.when() method </p> <button onclick = "Geeks();"> click here </button> <p id="GFG_DOWN"> </p> <script> 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 when() method P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies jQuery-Methods Similar Reads JQuery | now() method This now() Method in jQuery is used to return a number representing the current time. Syntax: jQuery.now() Parameters: The now() method does not accept any parameter. Return Value: It returns the number representing the current time. Example 1: In this example, the now() Method a display the number 1 min read JQuery | type() method This type() Method in jQuery is used to determine the internal JavaScript [[Class]] of an object. Syntax: jQuery.type( obj ) Parameters: The type() method accepts only one parameter that is mentioned above and described below: obj: This parameter is the object to get the internal JavaScript [[Class] 2 min read JQuery deferred.then() method This deferred.then() method in JQuery is used to add handlers which are to be called when the Deferred object is resolved, rejected, or in progress. Syntax: deferred.then(doneCallbacks[, failCallbacks][, progressCallbacks])Parameters: doneCallbacks: This is a function, or an array of functions, whic 3 min read JQuery | isArray() method This isArray() Method in jQuery is used to determines whether the argument is an array. Syntax: jQuery.isArray( object ) Parameters: The isArray() method accepts only one parameter that is mentioned above and described below: object : This parameter is the object to test whether or not it is an arra 2 min read JQuery hasData() method This hasData() method in JQuery is used to determine whether an element has any jQuery data associated with it. This data may be text, event associated with element. There are two examples discussed below: Syntax: jQuery.hasData(element)Arguments: element: This parameter is a DOM element which is to 2 min read Like