The Wayback Machine - https://web.archive.org/web/20230512160522/https://www.geeksforgeeks.org/jquery-callbacks-lock-method/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

jQuery callbacks.lock() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 callbacks object onto which it is attached.

Example 1: This example first adds and fires the function, then locks the callbacks list and then again adds and fires the function.




<!DOCTYPE HTML>
<html>
  
<head>
    <script src=
    </script>
</head>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
  
    <p>
        JQuery | callbacks.lock() 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 func = function (val) {
                res = res + 
                    "value passed is - " + val;
            };
  
            // Function added to list
            callbacks.add(func);
            callbacks.fire("gfg_1");
  
            // Locking the callback list
            callbacks.lock(); 
  
            // Function again added to list
            callbacks.add(func); 
            callbacks.fire("gfg_2");
            el_down.innerHTML = res;
        } 
    </script>
</body>
  
</html>

Output:

Example 2: This example provides a button to lock the list and then add and fire the function to check whether the method is working or not.




<!DOCTYPE HTML>
<html>
  
<head>
    <script src=
    </script>
</head>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
  
    <p>
        JQuery | callbacks.lock() method
    </p>
  
    <button onclick="Geeks();">
        click here
    </button>
      
    <button onclick="lock();">
        lock here
    </button>
      
    <p id="GFG_DOWN"></p>
  
    <script>
        var el_down = document
                .getElementById("GFG_DOWN");
  
        var res = "";
        var callbacks = jQuery.Callbacks();
        function lock() {
            callbacks.lock();
        }
        function Geeks() {
  
            // Function to be added to the list
            var fun = function (val) {
                res = res + "This is function and "
                + "value passed is " + val + "<br>";
            };
  
            callbacks.add(fun); // Adding
            callbacks.fire("GFG_1");
            el_down.innerHTML = res;
        } 
    </script>
</body>
  
</html>

Output:


My Personal Notes arrow_drop_up
Last Updated : 10 Jul, 2020
Like Article
Save Article
Similar Reads
Related Tutorials