Blinking Images With Javascript

I needed to have an image blink in one of our intranet applications today, so I wrote this quick javascript to accomodate. There aren’t many good image blinker scripts online, so I’m adding mine to the mix:

Start by adding this to your javascript file:

function blinkId(id) {
	var i = document.getElementById(id);
	if('hidden') {'visible';
	} else {'hidden';
	return true;

And this right before you end your <html> tag:

<script type="text/javascript">blinkId('YOUR_ELEMENT_ID');</script>

This will work for images, divs, spans, pretty much any block level element with an id.

Updated 8/19/2008: Fixed a copy/paste bug in this post.

Tagged ,

13 thoughts on “Blinking Images With Javascript

  1. Ivan says:

    The correct is:
    return true;

  2. Adam S says:

    Huh.. I typed it backwards. Obviously, I’m using the solution for real – the real code has it right. Not sure how I transposed it wrong.

  3. Me says:

    I just pinched this code (knowing very little JS) and swore for a while because it wouldn’t work.

    Copy and paste into TextMate resulting in some weird versions of apostrophes and quote marks, as if it was using smart quotes. I had to delete them all and retype them manually to get it to work.

  4. Sasha says:

    It was exactly what I wanted. The script helped. Thanks a ton

  5. patrick says:

    is there a working example of this somewhere? i can’t get it to work

  6. Ran says:

    Blinking Images With Javascript

    Thanks lot its working….

  7. Wale Adebayo says:

    Thanks, it worked.

  8. gtyuy says:


  9. Assa says:

    Thanks it works good….

  10. mawelewele mpho says:

    can you please send me code of how to make a picture blinking .tnx

  11. mini says:

    Can i know where the image id and the source of the image where it is would be given. how will it get the image

  12. I tried the above example with Ivan update as well, no luck. Can someone let me know how to make the text blink?

  13. Denz says:

    This works great, but is there a way to make it blink just once? Thanks for posting!

Leave a Reply

Your email address will not be published. Required fields are marked *