<!DOCTYPE HTML>
<
html
>
<
head
>
<
title
>
jQuery callbacks.add() method
</
title
>
<
script
src=
</
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");
var el_down = document.getElementById("GFG_DOWN");
el_up.innerHTML =
"JQuery | callbacks.add() method";
var res = "";
function Geeks() {
// First function to be added to the list
var fun1 = function (val) {
res = res + "This is function 1 and"
+ " value passed is " + val + "<
br
>";
};
// Second function to be added to the list
var fun2 = function (val) {
res = res + "This is function 2 and "
+ "value passed is" + val + "<
br
>";
};
var callbacks = jQuery.Callbacks();
// Adding the function 1
callbacks.add(fun1);
// Calling the function 1
callbacks.fire("GFG_1");
// Adding the function 2
callbacks.add(fun2);
// Calling the function 2
callbacks.fire("GFG_2");
// res of the both functions
el_down.innerHTML = res;
}
</
script
>
</
body
>
</html