Here is an easy way to do this using regular JavaScript:
function flash() { var text = document.getElementById('foo'); text.style.color = (text.style.color=='red') ? 'green':'red'; } var clr = setInterval(flash, 1000);
This will alternate the text color between red and green every second. jsFiddle example.
Here is another example where you can set the colors of different elements:
function flash(el, c1, c2) { var text = document.getElementById(el); text.style.color = (text.style.color == c2) ? c1 : c2; } var clr1 = setInterval(function() { flash('foo1', 'gray', 'red') }, 1000); var clr2 = setInterval(function() { flash('foo2', 'gray', 'blue') }, 1000); var clr3 = setInterval(function() { flash('foo3', 'gray', 'green') }, 1000);
and jsFiddle to go with it. You pass in the identifier of the element you want to flash, and the two colors you want to alternate.
source share