jQuery deferred.rejectWith() Method
Last Updated :
10 Jul, 2020
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:
- context: This parameter is the context passed to the failCallbacks as the ‘this’ object.
- args: This parameter is an optional array of arguments which are passed to the failCallbacks.
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:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...