Search This Blog

Thursday, May 6, 2010

How to set interval in javascript

Copy and save the entire code as a html file and see the result.

<html>
<head>
<script type="text/javascript">
function fls()
{
var date1 = new Date();
if(document.getElementById('spa1').style.color == 'red')
{

document.getElementById('spa1').style.color = 'blue';

}
else
{
document.getElementById('spa1').style.color = 'red';

}
document.getElementById('spa1').innerText = date1;
setTimeout('fls()',1000);

}
</script>
</head>
<body onload="javascript:fls();">
<div id='spa1' style='color: red;font-weight:bold;'> New </div>

</body>
</html>

No comments:

Post a Comment