Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Without a Callback (the bug)</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style> #box{width:150px;height:80px;background:#e57373;color:#fff;display:flex;align-items:center;justify-content:center;margin-bottom:10px;} </style> </head> <body> <button id="btn">Fade Out and Remove</button> <div id="box">Box</div> <div id="status" style="font-weight:bold;"></div> <script> $("#btn").on("click", function () { $("#status").text(""); $("#box").fadeOut(1500); $("#box").remove(); // runs immediately -- box disappears instantly, fade never seen! $("#status").text("Removed! (notice the fade never actually played)"); }); </script> </body> </html>
Output