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
  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events
  • jQuery Effects
  • jQuery Traversing
  • jQuery HTML & CSS
  • jQuery AJAX
  • jQuery Properties
  • jQuery Examples
  • jQuery Interview Questions
  • jQuery Plugins
  • jQuery Cheat Sheet
  • jQuery UI
  • jQuery Mobile
  • jQWidgets
  • Easy UI
  • Web Technology
Open In App
Next Article:
jQuery Deferred .promise() method
Next article icon

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:

p1-ezgifcom-optimize

Next Article
jQuery Deferred .promise() method

P

PranchalKatiyar
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
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