Jquery Promises

by black strings

HTML

<h1>Promise Testing on Browser</h1>
<p>After 3 seconds the message below will update if promise is working</p>
<div id="test"><span class="initme">Promise Starting ....</span></div>

CSS

.success {color:green}
.initme {color:red}
#test {
  display:inline-block;
  width:90%;
  border:thin solid grey;
  padding:10px;
}

JavaScript

var s="Promise Testing On Browser";
$.when(init()).then(function(){
	$('#test').html('<span class="success">Promise Complete [Success]</span>');
});

function init(){
	var def = $.Deferred();
  
  setInterval(function(){
  	  def.resolve();
  }, 3000);

  
  return def.promise();
}