This javascript incorporates several unusual features, in spite of being simple and short. The date and time are written directly into text: , whereas most scripts put it in the title bar, at the top of the page. I use a dynamic html element called innerText to allow us to update part of the text. Without that, we would probably lose the page. The span and /span tags are used to incorporate the date and time variable without a line break. The runClock function is started on loading the html page, using the onLoad command. this script will not run without that, though there may be other ways of starting the function. The method setInterval() is now applied to repeat a line of code within the function. Previously, I used setTimeout to repeat the runClock() function. Note the setInterval call - the line of code is in quotes. Note the reference to id = myClock, where myClock is a variable. Without that, the command myClock.innerText is not recognised - it must relate to an object. I formatted the date and clock using the command toLocaleString, rather than the usual toString which introduces an unattractive reference to UTC - corrected universal time. there's no point in having UTC on a computer. I set the interval to 500ms, though the cpu power used is registered as zero even if the interval is reduced to 100ms. This script runs in IE and Opera - not Firefox.
<body onload="runClock()">
<script language="javascript" type="text/javascript">
function runClock()
{
window.setInterval("window.myClock.innerText = (new Date()).toLocaleString()", 500);
}
</script>