Thursday, February 5, 2026
HomeLanguagesJavascriptJQuery deferred.state() method

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.




    <!DOCTYPE HTML> 
    <html>  
    <head
        <title
          JQuery | deferred.state() method
        </title>
    </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 | deferred.state() method";
            var def = $.Deferred();
            function Geeks() {
             $('#GFG_DOWN').text('deferred state is ' + def.state());
            
        </script
    </body>   
    </html>

    
    
  • Output:
  • Example: In this example, the state of deferred object ‘def’ is pending and by clicking on the button it changes to resolved.




    <!DOCTYPE HTML> 
    <html>  
    <head
        <title
          JQuery | deferred.state() method
        </title>
    </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 | deferred.state() method";
            var def = $.Deferred();
            def.always(Func);
            $('#GFG_DOWN').append(
              'Deferred state is ' + def.state() + '</br>');
            function Func(val, div){
              $(div).append(val);
            }
            function Geeks() {
                def.resolve(
          'Our deferred is resolved now. <br />', '#GFG_DOWN');
                $('#GFG_DOWN').append( 
    'Current state of deferred is ' + def.state() + ' <br />');
            
        </script
    </body>   
    </html>

    
    
  • Output:
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32487 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6861 POSTS0 COMMENTS
Nicole Veronica
11983 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12071 POSTS0 COMMENTS
Shaida Kate Naidoo
6994 POSTS0 COMMENTS
Ted Musemwa
7233 POSTS0 COMMENTS
Thapelo Manthata
6944 POSTS0 COMMENTS
Umr Jansen
6926 POSTS0 COMMENTS