Jquery Promise Example - Jquery

What is promise method in jquery?

Snippet Code


  
Rate this page :
  [ 0 votes]

Promise method in jquery is used to manage async events. Promise method is returned to check the actions of a certain type of collections are queued or not, or have finished or not. This method call will be resolved when all function have ended.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> $(document).ready(function(){ $( "button" ).on( "click", function() { $( "p" ).append( "Started..." ); $( "div" ).each(function( i ) { $( this ).fadeIn().fadeOut( 1000 * ( i 1 ) ); }); $( "div" ).promise().done(function() { $( "p" ).append( " Finished! " ); }); }); }); </script> <style> div { height: 50px; width: 50px; float: left; margin-right: 10px; display: none; background-color: pink; } </style> <button>Click</button> <p>Ready..</p> <div></div> <div></div> <div></div>

Tags


Ask Questions

Ask Question