JSFiddle - React, Tailwind, and code Playground
HTML
<div id="test" style="width:200px;height:200px;background:#000;"></div>
JavaScript
var colors = [
'#ccc',
'green',
'red',
'blue',
'white'
];
var index = 0;
function getNextColor() {
if (index >= colors.length) {
index = 0;
}
return colors[index++];
}
document.getElementById('test').onclick = function() {
this.style.background = getNextColor();
}