You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Function proto-type

setTimeout(function, milliseconds, param1, param2, ...)

Below code shows "Hello" after 3 seconds

setTimeout(function(){ alert("Hello"); }, 3000);

Below code shows increased number in innerHTML every 3 seconds

<html>
<script>
var myCnt=0;

function alertFunc() {
	myCnt++;
	document.getElementById( "main").innerHTML = myCnt;
	setTimeout(alertFunc, 3000); // repeat the same event
}

setTimeout(alertFunc, 3000);
</script>
<body>
<div id="main">The number will be increased and displayed here every 3 seconds</div>
</body>
</html>
  • No labels