jQuery callbacks.has() Method

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.



filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

Example 2: This example returns “false” because ‘func2’ is not in the list.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.