Q:

Resolve a deferred object when the user clicks a button, triggering a number of callback functions using jquery

0

Resolve a deferred object when the user clicks a button, triggering a number of callback functions using jquery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Resolve a deferred object when the user clicks a button, triggering a number of callback functions:</title>
</head>
<body>
<button>Go</button>
<p>Ready...</p>
</body>
</html>

JavaScript Code :

function f1() {
$( "p" ).append( "Ex.-1 " );
  }
  function f2() {
  $( "p" ).append( "Ex.-2 " );
  }
  function f3( n ) {
  $( "p" ).append( n + "Ex.-3 " + n );
  }
   // Create a deferred object
  var dfdobj = $.Deferred();
   // Add handlers to be called when dfd is resolved
  dfdobj
  // .done() can take any number of functions or arrays of functions
  .done( [ f1, f2 ], f3, [ f2, f1 ] )
  // We can chain done methods, too
  .done(function( n ) {
  $( "p" ).append( n + " we have done." );
  });
// Resolve the Deferred object when the button is clicked
  $( "button" ).on( "click", function() {
  dfdobj.resolve( "and " );
  });

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now