<div id="test"></div>
body{ color: red; } #test{ width: 100px; height: 100px; background-color: green; }
var gb_color = ['red','green','yellow'] var index = 0; document.getElementById('test').addEventListener('click',function(){ this.style.backgroundColor = gb_color[index] index+=1 index = index > 2?0:index; })