Blinking Element in Javascript

We can apply the blinking feature in any element with the feature of javascript. In this example we take an paragraph(p1). To apply the feature of blinking we set the timer in javascript, which call the function again and again after a particular time period.

timer=setTimeout("blinkmypara()",200); 

<html>
<head>
<script type="text/javascript">
function blinkmypara()
{
if (!document.getElementById('p1').style.color)
{
document.getElementById('p1').style.color="red";
}
if (document.getElementById('p1').style.color=="red")
{
document.getElementById('p1').style.color="green";
}
else
{
document.getElementById('p1').style.color="red";
}
if (document.getElementById('p1').style.color=="green")
{
document.getElementById('p1').style.color="blue";
}
else
{
document.getElementById('p1').style.color="red";
}
timer=setTimeout("blinkmypara()",200);
}

function stoptimer()
{
clearTimeout(timer);
}
</script>
</head>

<body onload="blinkmypara()" onunload="stoptimer()">
<p id="p1">Mahak</p> 
</body>

</html>

Ebook Download
View all
Learn
View all