<!DOCTYPE HTML>
<
html
>
<
head
>
<
title
>
JQuery callbacks.empty() method
</
title
>
<
script
src
=
</
script
>
</
head
>
<
body
style
=
"text-align:center;"
>
<
h1
style
=
"color:green;"
>
GeeksForGeeks
</
h1
>
<
p
>
JQuery | callbacks.empty() method
</
p
>
<
button
onclick
=
"Geeks();"
>
click here
</
button
>
<
p
id
=
"output"
></
p
>
<
script
>
var output = document.getElementById("output");
var res = "";
// Initialize a callback list
var callbacks = jQuery.Callbacks();
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
>";
};
// Adding the first function
callbacks.add(fun1);
// Calling the first function
callbacks.fire("GFG_1");
// Clearing the callback list
callbacks.empty();
// Adding the second function
callbacks.add(fun2);
// Calling the first function
callbacks.fire("GFG_2");
output.innerHTML = res;
}
</
script
>
</
body
>
</
html
>