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">
</div>
</body>
</html> |