JQuery deferred.notify() method
This deferred.notify() method in JQuery is used to call the progressCallbacks on a Deferred object with the given parameters.
Syntax:
deferred.notify(params)
Parameters:
- params: This is optional parameters which are passed to the progressCallbacks.
Return Value: This method method returns the deferred object.
There are two examples discussed below:
-
Example: In this example, The notify() is called with the arguments.
<!DOCTYPE HTML>
<
html
>
<
head
>
<
title
>
JQuery | deferred.notify() method
</
title
>
<
script
src
=
"https://code.jquery.com/jquery-3.5.0.js"
>
</
script
>
</
head
>
<
body
style
=
"text-align:center;"
>
<
h1
style
=
"color:green;"
>
w3wiki
</
h1
>
<
p
id
=
"GFG_UP"
>
</
p
>
<
button
onclick
=
"Beginner();"
>
click here
</
button
>
<
p
id
=
"GFG_DOWN"
>
</
p
>
<
script
>
var el_up = document.getElementById("GFG_UP");
el_up.innerHTML = "JQuery | deferred.notify() method";
function Func(val, div){
$(div).append('From function "Func": ' + val);
}
function Beginner() {
var def = $.Deferred();
def.progress(Func);
def.notify(
'notify() is called with arguments. <
br
/>', '#GFG_DOWN');
}
</
script
>
</
body
>
</
html
>
-
Output:
-
Example: In this example, The notify() is called without arguments.
<!DOCTYPE HTML>
<
html
>
<
head
>
<
title
>
JQuery | deferred.notify() method
</
title
>
<
script
src
=
"https://code.jquery.com/jquery-3.5.0.js"
>
</
script
>
</
head
>
<
body
style
=
"text-align:center;"
>
<
h1
style
=
"color:green;"
>
w3wiki
</
h1
>
<
p
id
=
"GFG_UP"
>
</
p
>
<
button
onclick
=
"Beginner();"
>
click here
</
button
>
<
p
id
=
"GFG_DOWN"
>
</
p
>
<
script
>
var el_up = document.getElementById("GFG_UP");
el_up.innerHTML = "JQuery | deferred.notify() method";
function Func(val, div){
$(div).append('From function "Func": ' + val);
}
function Beginner() {
var def = $.Deferred();
def.done(Func);
def.progress(Func);
def.notify();
def.resolve('Deferred is resolved.<
br
/>', '#GFG_DOWN')
}
</
script
>
</
body
>
</
html
>
-
Output: