JSFiddle - React, Tailwind, and code Playground
HTML
<div id="box">
</div>
<div id="colorvalue"></div>
CSS
#box
{
height: 100px;
width: 100px;
}
JavaScript
/* A function to return random number from min to max */
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
setInterval(function() {
var element = document.getElementById("box");
//generate random red, green and blue intensity
var randomColor = Math.floor(Math.random()*16777215).toString(16);
var r = getRandomInt(0, 255);
var g = getRandomInt(0, 255);
var b = getRandomInt(0, 255);
element.style.backgroundColor = '#' + randomColor;
}, 1500);