Open In App
Related Articles

jQuery callbacks.has() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
The callbacks.has() method in jQuery is used to answer whether the list has any callbacks attached. If a callback is passed as an argument, then it answers whether it is on the list or not. Syntax:
callbacks.has([callback])
Parameters:
  • callback: The parameter defines the callback to search for, in the list.
Return Value: This method either returns true or false. Example 1: This example returns “true” because ‘func’ is in the list.
<!DOCTYPE HTML>
<html>
  
<head>
    <script src=
    </script>
</head>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
  
    <p>
        JQuery | callbacks.has() method
    </p>
      
    <button onclick="Geeks();">
        click here
    </button>
      
    <p id="GFG"></p>
  
    <script>
        var el_down = document.getElementById("GFG");
        var res = "";
        var callbacks = jQuery.Callbacks();
          
        function Geeks() {
            var func = function (val) {
                res = res + "value passed is - " + val;
            };
            callbacks.add(func); // function added to list
            callbacks.fire("gfg_1");
            el_down.innerHTML = callbacks.has();
        
    </script>
</body>
  
</html>

                    
Output: Example 2: This example returns “false” because ‘func2’ is not in the list.
<!DOCTYPE HTML>
<html>
  
<head>
    <script src=
    </script>
</head>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
  
    <p>
        JQuery | callbacks.has() method
    </p>
      
    <button onclick="Geeks();">
        click here
    </button>
      
    <p id="GFG_DOWN"></p>
  
    <script>
        var el_down = document.getElementById("GFG_DOWN");
        var res = "";
        var callbacks = jQuery.Callbacks();
  
        function Geeks() {
            var func1 = function (val) {
                res = res + "value passed is - " + val;
            };
            var func2 = function (val) {
                res = res + "value passed is - " + val;
            };
  
            // Function added to list
            callbacks.add(func1); 
            callbacks.fire("gfg_1");
            el_down.innerHTML = callbacks.has(func2);
        
    </script>
</body>
  
</html>

                    
Output:

Last Updated : 10 Jul, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads