# deferred.done()

## deferred.done ( doneCallbacks, doneCallbacks ) Returns: Deferred version added: 1.5

- doneCallbacks
  Type: Function
  A function, or array of functions, that are called when the Deferred is resolved.

- doneCallbacks
  Type: Function
  Optional additional functions, or arrays of functions, that are called when the Deferred is resolved.

Description: Add handlers to be called when the Deferred object is resolved.

The `deferred.done()` method accepts one or more arguments, all of which can be either a single function or an array of functions. When the Deferred is resolved, the doneCallbacks are called. Callbacks are executed in the order they were added. Since `deferred.done()` returns the deferred object, other methods of the deferred object can be chained to this one, including additional `.done()` methods. When the Deferred is resolved, doneCallbacks are executed using the arguments provided to the `resolve` or `resolveWith` method call in the order they were added. For more information, see the documentation for Deferred object.

## Examples:

#### Example: Since the jQuery.get method returns a jqXHR object, which is derived from a Deferred object, we can attach a success callback using the .done() method.

    $.get( "test.php" ).done(function() {
      alert( "$.get succeeded" );
    });

#### Example: Resolve a Deferred object when the user clicks a button, triggering a number of callback functions:

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>css demo</title>

      <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    </head>
    <body>

    <button>Go</button>
    <p>Ready...</p>

    <script>

    // 3 functions to call when the Deferred object is resolved
    function fn1() {
      $( "p" ).append( " 1 " );
    }
    function fn2() {
      $( "p" ).append( " 2 " );
    }
    function fn3( n ) {
      $( "p" ).append( n + " 3 " + n );
    }

    // Create a deferred object
    var dfd = $.Deferred();

    // Add handlers to be called when dfd is resolved
    dfd
    // .done() can take any number of functions or arrays of functions
      .done( [ fn1, fn2 ], fn3, [ fn2, fn1 ] )
    // We can chain done methods, too
      .done(function( n ) {
        $( "p" ).append( n + " we're done." );
      });

    // Resolve the Deferred object when the button is clicked
    $( "button" ).on( "click", function() {
      dfd.resolve( "and" );
    });

    </script>

    </body>
    </html>

#### Demo: