JQuery में callback functions का उपयोग एनीमेशन के मौजूदा प्रभाव के निष्पादन को रोकने के लिए किया जाता है चूंकि जावास्क्रिप्ट में statements line by line को executed करता है
वर्तमान प्रभाव के समाप्त होने के बाद callback फ़ंक्शन को executed किया जाता है javascript पंक्ति द्वारा कोड लाइन को executed करता है हालांकि, प्रभाव के साथ,
कोड की अगली पंक्ति चल सकती है भले ही प्रभाव समाप्त न हुआ हो यहां पर errors बना सकता है इसे रोकने के लिए, आप एक callback फ़ंक्शन बना सकते हैं।
$(selector).hide(speed,callback);
उपरोक्त वाक्य रचना की मदद से, त्रुटियों को रोकना आसान हुआ है और कार्यक्रम को सफलतापूर्वक चलाया जा सकता है
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("h4").hide("slow", function(){ alert("The paragraph is now hidden"); }); }); }); </script> </head> <body> <button>Hide</button> <h4>This is fourth my heading.</h4> </body> </html>