JQuery callbacks.disable() method

This callbacks.disable() method in JQuery is used to disable a callback list from doing any other operation further. This method returns the Callbacks object onto which it is attached (this)
Syntax:
callbacks.disable()
There are two examples discussed below:
-
Example: This example disables the callback after adding and firing a function.
<!DOCTYPE HTML>Â<html> Â<head>   Â<title>     ÂJQuery | callbacks.disable() method   Â</title>   Â<scriptsrc=</head>  Â<bodystyle="text-align:center;">   Â<h1style="color:green;"> Â       ÂGeeksForGeeks Â   Â</h1>   Â<pid="GFG_UP">   Â</p>   Â<buttononclick="Geeks();">   Âclick here   Â</button>   Â<pid="GFG_DOWN">   Â</p>      Â   Â<script>       Âvar el_up = document.getElementById("GFG_UP");       Âvar el_down = document.getElementById("GFG_DOWN");       Âel_up.innerHTML = "JQuery | callbacks.disable() 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();           Âcallbacks.add(fun1); // adding the function 1           Âcallbacks.fire("GFG_1"); // calling the function 1           Âcallbacks.disable(); /*disables further calls                                  Âto a callback list*/           Âcallbacks.add(fun2); // This will not work.           Âcallbacks.fire("GFG_2"); // This will not work.           Âel_down.innerHTML = res;       Â}   Â</script>Â</body>  Â</html>     -
Output:
-
Example: This example provides a button to first disable the callbacks and then add and fire the method to see the result.
<!DOCTYPE HTML>Â<html> Â<head>   Â<title>     ÂJQuery | callbacks.disable() method   Â</title>   Â<scriptsrc=</head>  Â<bodystyle="text-align:center;">   Â<h1style="color:green;"> Â       ÂGeeksForGeeks Â   Â</h1>   Â<pid="GFG_UP">   Â</p>   Â<buttononclick="Geeks();">   Âclick here   Â</button>   Â<buttononclick="disable();">   Âdisable   Â</button>   Â<pid="GFG_DOWN">   Â</p>      Â   Â<script>       Âvar el_up = document.getElementById("GFG_UP");       Âvar el_down = document.getElementById("GFG_DOWN");       Âel_up.innerHTML = "JQuery | callbacks.disable() method";       Âvar res = "";       Âvar callbacks = jQuery.Callbacks();       Âfunction disable() {           Âcallbacks.disable();       Â}       Â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>";           Â};           Âcallbacks.add(fun1); // adding the function 1           Âcallbacks.fire("GFG_1"); // calling the function 1           Âcallbacks.add(fun2); // This will not work.           Âcallbacks.fire("GFG_2"); // This will not work.           Âel_down.innerHTML = res;       Â}   Â</script>Â</body>  Â</html>    Â -
Output:
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



