JSFiddle - React, Tailwind, and code Playground
HTML
<div id="myID"></div>
CSS
#myID{
width: 100px;
height: 100px;
background-color: blue;
}
JavaScript
var i = 0;
function changecolor()
{
var thesquare = document.getElementById('myID');
switch (i)
{
case 0 :
thesquare.style.backgroundColor = "red";
thesquare.style.opacity = "0.50";
++i;
break;
case 1 :
thesquare.style.backgroundColor = "green";
++i;
break;
default :
thesquare.style.backgroundColor = "blue";
i=0;
break;
}
}
setInterval(changecolor,1000);