JSFiddle - React, Tailwind, and code Playground
HTML
<div id="button">Activate</div>
<div id="button">Activate</div>
<div id="box"></div>
<div id="box1"></div>
CSS
#button {
padding: 10px 20px;
width: 50px;
height: 20px;
background: blue;
color: #fff;
}
#box {
margin: 200px;
width: 200px;
height: 200px;
background-color: gray;
}
JavaScript
var button = $("#button"),
box = $('#box'),
box = $('#box1');
button.on("click", colorLoop);
function colorLoop() {
var colors = ["red","yellow", "green", "purple", "gray"],
n = 0;
// Initial click ( Changes color instantly )
changeColor( colors[0] );
// Changes color with 500ms delay...
setInterval(function() {
n = n === colors.length-1 ? 0 : n+1;
changeColor( colors[n] );
}, 500 );
}
function changeColor( c ) {
box.css({ backgroundColor: c });
}