Home  >  jQuery

Example of deferred.done() in jQuery

April 30, 2013
deferred.done() adds handlers or functions and makes an ordered collection. All these handlers is called when deferred object is resolved. Syntax is
var def = $.Deferred();
def.done(handlers)
def. resolve()
 
Find the example.

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<button>Click To Test deferred.done()</button>
<div></div>
<script>

function fun1() {
 $("div").append(" You ");
}
function fun2() {
$("div").append(" are ");
}
function fun3(str) {
$("div").append(" on  " + str);
}
/* create a deferred object */
var def = $.Deferred();

def.done( fun1, fun2, fun3)

$("button").on("click", function() {
def.resolve("concretepage.com");
});

</script>
</body>
</html>
 




Output
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us