JQuery Callback

 

As we know javascript code run line by line and sometimes the current line effect is still in progress but the next line executes and this creates an error.
To prevent this, we can create callback functions.


In this example, we have used a callback parameter that is a function that will be executed and will be showing an alert message after the hide effect is completed.

 
 
 
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("h1").hide("slow", function(){ alert("wow that's hide it"); }); }); }); </script> </head> <body> <button>Hide Me!!</button> <h1 style="color:darkred">you can experiment your code online with Learnkode
Output