Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
JQuery when() method
Next article icon

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:



Next Article
JQuery when() method

P

PranchalKatiyar
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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences