Learn jQuery

jQuery Callback

jQuery callback function is executed just after the current effect is 100% finished.As we know JavaScript code are executed line by line.But some times jQuery effect takes some time to finish the next line code may execute while the previous effect is still running. To Prevent this situation jQuery provides a callback function.

We can pass callback function as an argument to the effect methods and they typically appear as the last argument of the method.

Syntax

$(selector).show(speed,callback);

Examples

jQuery Callback Example

<!DOCTYPE html> 
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<title>jQuery Callback Example </title>
</head>
<body>
<button>Click Me</button>
<div style="height:100px;width:200px;display:none;">
Use of jQuery Callback
</div>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
    $("button").click(function(){
        $("div").show("slow", function(){
            alert("The paragraph is now visible");
        });
    });
});
</script>