Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>delay() & complete callback</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style>#box{width:120px;height:60px;background:#c5e1a5} #log{white-space:pre}</style> </head> <body> <button id="run">Run</button> <div id="box"></div> <pre id="log"></pre> <script> $("#run").on("click", function(){ $("#log").text(""); $("#box").fadeOut(200).delay(300).fadeIn(200, function(){ $("#log").append("complete callback fired\n"); }).promise().done(function(){ $("#log").append("$.promise() done\n"); }); }); </script> </body> </html>
Output