Skip to content
Related Articles

Related Articles

jQuery callbacks.fire() Method
  • Last Updated : 07 Jul, 2020

The jQuery callbacks.fire() method is used to call all the callbacks with the given arguments in the list. This method returns the callbacks object onto which it is attached (this).

Syntax:

callbacks.fire( arguments )

Parameters:

  • arguments: This parameter defines the argument or list of arguments to pass back to the callback list.

Return Value: This method returns the callbacks object onto which it is attached (this).

Example 1: This example adds the fun1() to the callbacks and then calls the fire() method and then again adds the same method calling the callbacks with a different argument.



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE HTML>
<html>
  
<head>
    <title>
        jQuery callbacks.fire() method
    </title>
  
    <script src=
    </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.fire() 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>";
            };
  
            // Adding the function 1
            callbacks.add(fun1);
  
            // Calling with 'GFG_1'
            callbacks.fire("GFG_1");
  
            // Adding the function 1 again
            callbacks.add(fun1); 
  
            // Calling with argument'GFG_2'
            callbacks.fire("GFG_2");
            el_down.innerHTML = result;
        
    </script>
</body>
  
</html>

chevron_right


Output:

Example 2: This example adds the 2 different functions and calls them with different arguments.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE HTML>
<html>
  
<head>
    <title>
        JQuery | callbacks.fire() method
    </title>
  
    <script src=
    </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.fire() method";
        var result = "";
        var callbacks = jQuery.Callbacks();
        function Geeks() {
            // function to be added to the list
            var fun1 = function (val) {
                result = result + "This is function 1 and"
                    + " value passed is " + val + "<br>";
            };
            var fun2 = function (val) {
                result = result + "This is function 2 and"
                    + " value passed is " + val + "<br>";
            };
            callbacks.add(fun1); // Adding the function 1
            callbacks.fire("GFG_1"); // Calling with 'GFG_1'
            callbacks.add(fun2); // Adding the function 2
            callbacks.fire("GFG_2"); // Calling with 'GFG_2'
            el_down.innerHTML = result;
        
    </script>
</body>
  
</html

chevron_right


Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :