Javascript – HTML flashing text colors

colorsfontshtmljavascript

This is quite an unusual request, but..

Is there anyway to make some text alternate between 2 colors every second?

So it appears as though it's flashing between say… red and grey? I don't mean background color, I mean the actual font color. I'm assuming it would need javascript or something.

Is there any simple way to do that?

(disregarding the fact it could look ugly)

UPDATE

Id like to call to this function several times on my page, each one passing along a different color to alternate with GREY

.

Best Solution

As per your request:

    function flashtext(ele,col) {
    var tmpColCheck = document.getElementById( ele ).style.color;

      if (tmpColCheck === 'silver') {
        document.getElementById( ele ).style.color = col;
      } else {
        document.getElementById( ele ).style.color = 'silver';
      }
    } 

    setInterval(function() {
        flashtext('flashingtext','red');
        flashtext('flashingtext2','blue');
        flashtext('flashingtext3','green');
    }, 500 ); //set an interval timer up to repeat the function

JSFiddle here: http://jsfiddle.net/neuroflux/rXVUh/14/

Related Question