jQuery callbacks.add() Method Last Updated : 23 Jul, 2024 Comments Improve Suggest changes Like Article Like Report The jQuery callbacks.add() method is used to add a callback or a collection of callbacks to a callback list. This method returns the callback object onto which it is attached (this).Syntax: callbacks.add(callbacks)Parameters: callbacks: This parameter holds a function, or an array of functions, that are to be added to the callback list.Example 1: This method adds a method fun1() to the callback and call it. html <!DOCTYPE HTML> <html> <head> <title> jQuery callbacks.add() method </title> <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 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.add() method"; var res = ""; function Geeks() { // First function to be added to the list var fun1 = function (val) { res = res + "This is function 1 and" + " value passed is " + val + "<br>"; }; var callbacks = jQuery.Callbacks(); callbacks.add(fun1); //Adding the func1 callbacks.fire("GFG_1"); // Calling the fun1 el_down.innerHTML = res; } </script> </body> </html> Output: Example 2: This example adds method fun1() and fun2() to the callbacks and then calls them. Notice that at second time the fire() method is called, it calls both the functions with the same argument 'GFG_2'. html <!DOCTYPE HTML> <html> <head> <title> jQuery callbacks.add() method </title> <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 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.add() method"; var res = ""; function Geeks() { // First function to be added to the list var fun1 = function (val) { res = res + "This is function 1 and" + " value passed is " + val + "<br>"; }; // Second function to be added to the list var fun2 = function (val) { res = res + "This is function 2 and " + "value passed is" + val + "<br>"; }; var callbacks = jQuery.Callbacks(); // Adding the function 1 callbacks.add(fun1); // Calling the function 1 callbacks.fire("GFG_1"); // Adding the function 2 callbacks.add(fun2); // Calling the function 2 callbacks.fire("GFG_2"); // res of the both functions el_down.innerHTML = res; } </script> </body> </html Output: Comment More infoAdvertise with us Next Article jQuery callbacks.add() Method P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JQuery jQuery-Methods Similar Reads jQuery addBack() Method The addBack() is an inbuilt method in jQuery that adds the previous set of elements to the current set. This method adds previous DOM tree elements to the current set and maintains them in the internal stack which will take care of changes to the matched set of elements. Syntax: .addBack(selector) P 2 min read 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 2 min read jQuery callbacks.fire() Method 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 pa 2 min read jQuery callbacks.lock() Method The callbacks.lock() method in jQuery is used to lock a callback list in the state. Syntax:callbacks.lock()Return Value: This method returns the callback object to which it is attached. Example 1:This example first adds and fires the function, then locks the callbacks list, and then again adds and f 2 min read jQuery callbacks.empty() Method The callbacks.empty() method in jQuery is used to remove all the callbacks from a list. It returns the Callbacks object onto which it is attached.Syntax:callbacks.empty()Parameters: It does not accept any parameter.Return Value: This method returns the Callbacks object onto which it is attached.Belo 3 min read Like