HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style> div{ width: 100px; height: 100px; background: #f69d3c; margin-top: 10px; line-height: 6; text-align: center; } </style> </head> <body> <h1>jQuery deferred.promise() Method</h1> <button>Animate</button> <div id="point1">div1</div> <div id="point2">div2</div> <script> $(document).ready(function(){ $("button").click(function(){ myAnimation("#point1", "fast"); myAnimation("#point2", "slow"); $("#point1, #point2").promise().done(function() { alert("All animations are completed"); }); }); function myAnimation(elem, speed){ $(elem).animate({width: 150}, speed); $(elem).animate({height: 150}, speed); $(elem).animate({width: 100}, speed); $(elem).animate({height: 100}, speed); } }); </script> </body> </html>
OUTPUT
×

Save as Private