Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>$.noop() and $.when()</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <button id="run">Run</button> <pre id="out"></pre> <script> $("#run").click(function(){ var a = $.Deferred(function(d){ setTimeout(function(){ d.resolve("A"); }, 200); }).promise(); var b = $.Deferred(function(d){ setTimeout(function(){ d.resolve("B"); }, 200); }).promise(); $.when(a, b).done(function(x, y){ $("#out").text("Done: " + x + ", " + y); }).fail($.noop); }); </script> </body> </html>
Output