I recently came across a timing event and have some doubts regarding the usage of setTimeout
. I found an example on W3Schools where it is set to run every 500 milliseconds. However, my understanding is that setTimeout
functions only once. You can view the example on W3Schools through this link.
<head>
<script>
function startTime() {
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
setTimeout(function(){startTime()},500);
}
</script>
</head>
<body onload="startTime()">
<div id="txt"></div>
</body>