Skip to content
Related Articles

Related Articles

jQuery callbacks.has() Method
  • Last Updated : 10 Jul, 2020

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
Recommended Articles
Page :