Blinking Element in Javascript

We can apply the blinking feature in any element with the feature of javascript. In this example, we take a paragraph(p1). To apply the feature of blinking we set the timer in javascript, which calls the function again and again after a particular time period.
  1. timer=setTimeout("blinkmypara()",200);
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function blinkmypara() {
  5. if (!document.getElementById('p1').style.color) {
  6. document.getElementById('p1').style.color = "red";
  7. }
  8. if (document.getElementById('p1').style.color == "red") {
  9. document.getElementById('p1').style.color = "green";
  10. } else {
  11. document.getElementById('p1').style.color = "red";
  12. }
  13. if (document.getElementById('p1').style.color == "green") {
  14. document.getElementById('p1').style.color = "blue";
  15. } else {
  16. document.getElementById('p1').style.color = "red";
  17. }
  18. timer = setTimeout("blinkmypara()", 200);
  19. }
  20. function stoptimer() {
  21. clearTimeout(timer);
  22. }
  23. </script>
  24. </head>
  25. <body onload="blinkmypara()" onunload="stoptimer()">
  26. <p id="p1">Mahak</p>
  27. </body>
  28. </html>