вот совсем по простому, к примеру
<body>
<span style ="color:black">text</span>
<button onclick ="clearInterval(timer)">PLEASE STOP!!!</button>
<script type = "text/javascript">
var element = document.body.children[0];
function changeTxtColor() {
var style = element.style;
if (style.color == "black")
element.style.color = "red";
else if (style.color == "red")
element.style.color = "green";
else
element.style.color = "black";
}
var timer = setInterval(changeTxtColor, 500);
</script>
</body>