HomeLanguagesJavascriptJQuery callbacks.disable() method

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>
        <script src=
    </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.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>
        <script src=
    </head>   
    <body style="text-align:center;">
        <h1 style="color:green;">  
            GeeksForGeeks  
        </h1> 
        <p id="GFG_UP"> 
        </p>
        <button onclick = "Geeks();">
        click here
        </button>
        <button onclick = "disable();">
        disable
        </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.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, neveropen 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!
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32548 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6924 POSTS0 COMMENTS
Nicole Veronica
12039 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12150 POSTS0 COMMENTS
Shaida Kate Naidoo
7060 POSTS0 COMMENTS
Ted Musemwa
7302 POSTS0 COMMENTS
Thapelo Manthata
7018 POSTS0 COMMENTS
Umr Jansen
7006 POSTS0 COMMENTS