Hello,
I am using a modified version of a jQuery example taken from:
http://api.jquery.com/promise/My code is below and I am just trying to understand the return statement used in this code:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>promise demo</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<button>Go</button>
<p>Ready...</p>
<div></div>
<div></div>
<div></div>
<script>
var effect = function() {
return $( "div" ).addClass('test');
};
$( "button" ).on( "click", function() {
$( "p" ).append( " Started... " );
$.when( effect() ).done(function() {
$( "p" ).append( " Finished! " );
});
});
</script>
</body>
</html>
Without the return above I get this in console:
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.
So what I have concluded is, "Without the return statement above, the chaining does not function correctly". Or another way of saying this is, "you need a return statement here in order for jQuery chaining to function correctly"
Is this the purpose of the return ?
Thanks,
Jim