JSFiddle - React, Tailwind, and code Playground
HTML
<div id="item"></div>
CSS
#item {
width: 100px;
height: 100px;
background: gray;
}
JavaScript
function colormake(){
var H = 359 * Math.random();
var S = (100-46) + 46 * Math.random() + '%';
var L = (100-46) + 46 * Math.random() + '%';
return 'hsl('+H+', '+S+'%, '+L+'%)';
}
var item = document.getElementById('item');
function changeBG(){
item.style.backgroundColor = colormake();
}
//-----------------------------------------
var ind = false;
item.onclick = function(){
if (!ind) {
var cy = setInterval(changeBG, 100);
ind = true;
} else {
clearInterval(cy);
ind = false;
}
};