Open In App

jQuery callbacks.fired() Method

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

The jQuery callbacks.fired() method is used to check if the callbacks have already been called at least once. This method returns the Boolean value.

Syntax:

callbacks.fired()

Parameters: This method does not accept any arguments.

Return Value: This method returns a Boolean value.

Example 1: This example returns true because the fire() method has been called at least once.

html
<!DOCTYPE HTML>
<html>

<head>
    <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>
        jQuery | callbacks.fired() method
    </p>

    <button onclick="Geeks();">
        Click Here
    </button>

    <p id="GFG_DOWN"></p>

    <script>
        let el_down = document.getElementById("GFG_DOWN");
        let res = "";
        let callbacks = jQuery.Callbacks();

        function Geeks() {

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

            // Adding the function 1
            callbacks.add(fun1);

            // Calling with "GFG_1"
            callbacks.fire("GFG_1");

            // Calling callbacks.fired()
            // method to get true
            el_down.innerHTML = callbacks.fired();
        } 
    </script>
</body>

</html>

Output:

jQuery-callbacksfired()-method-

Example 2: This example returns false because the fire() method hasn’t been called.

html
<!DOCTYPE HTML>
<html>

<head>
    <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>
        jQuery | callbacks.fired() method
    </p>

    <button onclick="Geeks();">
        Click Here
    </button>

    <p id="GFG_DOWN"></p>

    <script>
        let el_down = document.getElementById("GFG_DOWN");
        let res = "";
        let callbacks = jQuery.Callbacks();

        function Geeks() {

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

            // Adding the function 1
            callbacks.add(fun1);

            // Adding again
            callbacks.add(fun1);

            // Calling callbacks.fired() but 
            // This time we will get false
            el_down.innerHTML = callbacks.fired();
        } 
    </script>
</body>

</html>

Output:

jQuery-callbacksfired()-method---2


Next Article

Similar Reads