Blinking image

i’m doing some simple effect with js…

<img src="images/fire.png" id="fire" />




function blinkImg()
for(i=1;i<delay;i++) // creates delay between blinks

above code should create blinking image that blinks fast each single time but there is 1000ms betwen separate blinks
but it doesn’t work…but if i interchange lines (a) and (b) then it works(actually“none”; becomes redundent line)

from my attempts to understand what’s going on so far i came to think that there are some optimizations done on my code by js parser…in my case what happens is that only the last instruction is applyed.

am i thinking in the right direction?

Yes, you’re doing good, but I took a little different approach in the following demo. The image is visible for imgOnTime, and hidden for imgOffTime. If the image blinks while it is visible then that is a feature of the image and not of the script.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<style type='text/css'>
#fire {
  top:140px; left:100px;
<script type='text/javascript'>
var imgId = 'fire';
var imgOnTime = 250;
var imgOffTime = 750;
window.onload = function()
  // check for existence of objects we will use
  if (document.getElementById) {
    var ele = document.getElementById(imgId);
    if (ele && {
      setTimeout('blinkImg()', imgOffTime);
function blinkImg()
  var v, t, ele = document.getElementById(imgId);
  if ( == 'visible') {
    // hide it, then wait for imgOffTime
    v = 'hidden';
    t = imgOffTime;
  else {
    // show it, then wait for imgOnTime
    v = 'visible';
    t = imgOnTime;
  } = v;
  setTimeout('blinkImg()', t);
<p>The image is visible for imgOnTime, and hidden for imgOffTime.</p>
<img src="usflag.jpg" id="fire">

thank you
yet i’m very curious why my script doesn’t work…
do you know why??

just implemented your example and now it works beautifully
it is pitty you can see it:)
thanks a lot