//by Troy Whorten 3/6/2014 function timeout() { var x = document.getElementById("txt"); var msg = document.getElementById("msg"); setTimeout(function () { x.innerHTML = "0.2 seconds"; }, 200); var el = document.createElement("span"); el.innerHTML = "First setTimeout Called"; msg.appendChild(el); msg.appendChild(document.createElement("br")); setTimeout(function () { x.innerHTML = "0.4 seconds"; }, 400); el = document.createElement("span"); el.innerHTML = "Next setTimeout Called"; msg.appendChild(el); msg.appendChild(document.createElement("br")); setTimeout(function () { x.innerHTML = "0.6 seconds"; }, 600); el = document.createElement("span"); el.innerHTML = "Last setTimeout Called"; msg.appendChild(el); msg.appendChild(document.createElement("br")); }
<button onclick="timeout()">Run Code</button> <button onclick='document.getElementById("msg").innerHTML=""'>Clear</button> <br/> <span id="txt"></span> <div id="msg"></div>