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.
<!DOCTYPE HTML> < html > < head > < script src = "https://code.jquery.com/jquery-3.5.0.js" > </ script > </ head > < body style = "text-align:center;" > < h1 style = "color:green;" > w3wiki </ h1 > < p > JQuery | callbacks.has() method </ p > < button onclick = "Beginner();" > click here </ button > < p id = "GFG" ></ p > < script > var el_down = document.getElementById("GFG"); var res = ""; var callbacks = jQuery.Callbacks(); function Beginner() { 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 = "https://code.jquery.com/jquery-3.5.0.js" > </ script > </ head > < body style = "text-align:center;" > < h1 style = "color:green;" > w3wiki </ h1 > < p > JQuery | callbacks.has() method </ p > < button onclick = "Beginner();" > click here </ button > < p id = "GFG_DOWN" ></ p > < script > var el_down = document.getElementById("GFG_DOWN"); var res = ""; var callbacks = jQuery.Callbacks(); function Beginner() { 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:
Contact Us