Open In App

jQuery deferred.rejectWith() Method

This deferred.rejectWith() method in jQuery is used to reject a Deferred object and call the failCallbacks along with the given context and arguments.

Syntax:



deferred.rejectWith(context[, args])

Parameters:

Return Value: This method returns the deferred object.



Example 1: In this example, we reject the Deferred object with two arguments and process any failCallbacks.




<!DOCTYPE HTML>
<html>
  
<head>
    <script src=
    </script>
</head>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
  
    <p>
        JQuery | deferred.rejectWith() method
    </p>
      
    <button onclick="Geeks();">
        click here
    </button>
      
    <p id="GFG_DOWN"></p>
  
    <script>
        function Func(val, div) {
            $(div).append(val);
        }
  
        function Geeks() {
            var def = $.Deferred();
            def.fail(Func);
            def.rejectWith(this, 
['Deferred is rejected by rejectWith() method.<br/>',
                '#GFG_DOWN']);
        
    </script>
</body>
  
</html

Output:

Example 2: In this example, we reject the Deferred object with only one arguments and process any failCallbacks.




<!DOCTYPE HTML>
<html>
  
<head>
    <script src=
    </script>
</head>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
  
    <p>
        JQuery | deferred.rejectWith() method
    </p>
      
    <button onclick="Geeks();">
        click here
    </button>
      
    <p id="GFG_DOWN"></p>
  
    <script>
        function Func(div) {
            $(div).append(
'Deferred is rejected by rejectWith() method');
        }
  
        function Geeks() {
            var def = $.Deferred();
            def.fail(Func);
            def.rejectWith(this, ['#GFG_DOWN']);
        
    </script>
</body>
  
</html>  

Output:


Article Tags :