Open In App

jQuery callbacks.disabled() Method

Last Updated : 24 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The jQuery callbacks.disabled() method is used to check if the callback is disabled or not. This method returns “true” or “false” depending on the callback.

Syntax:

callbacks.disabled()

Return Value:

This method returns a boolean value.

Example 1:

This example disables the callback and then call the callbacks.disabled() method to see the result.

html
<!DOCTYPE HTML>
<html>

<head>
    <title>
        jQuery callbacks.disabled() method
    </title>

    <script src=
"https://code.jquery.com/jquery-3.5.0.js">
    </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.disabled() method";

        var result = "";
        var callbacks = jQuery.Callbacks();

        function Geeks() {
        
            // First function to be added to the list
            var fun1 = function (val) {
                result = result + "This is function 1 and"
                    + " value passed is " + val + "<br>";
            };

            callbacks.add(fun1); // Adding the function 1
            callbacks.fire("GFG_1"); // Calling the function 1
            callbacks.disable();
            el_down.innerHTML = callbacks.disabled();
        } 
    </script>
</body>

</html>

Output:


Example 2:

This example provides a

button

to disable the callbacks and check then.

html
<!DOCTYPE HTML>
<html>

<head>
    <title>
        jQuery callbacks.disabled() method
    </title>

    <script src=
"https://code.jquery.com/jquery-3.5.0.js">
    </script>
</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.disabled() method";
        var result = "";
        var callbacks = jQuery.Callbacks();
        function disable() {
            callbacks.disable();
        }
        function Geeks() {

            // First function to be added to the list
            var fun1 = function (val) {
                result = result + "This is function 1 and"
                    + " value passed is " + val + "<br>";
            };
            callbacks.add(fun1); // Adding the function 1
            callbacks.fire("GFG_1"); // Calling the function 1
            el_down.innerHTML = callbacks.disabled();
        } 
    </script>
</body>

</html>

Output:




Next Article

Similar Reads