JSFiddle - React, Tailwind, and code Playground

HTML

<div id="div-1"></div>    
<div id="div-2"></div>    
<div id="div-3"></div>

CSS

div {
    width: 100px;
    height: 100px;
    margin: 10px;
    border: 1px solid #000;
}

div.clicked-1 {
    background: blue;
}

div.clicked-2 {
    background: red;
}

div.clicked-3 {
    background: green;
}

JavaScript

$(function(){
   var interval;
    
   $('div').on('click', function(){
       $('div').removeClass();
       clearInterval(interval);
       
       interval = setInterval(function(){
            $('div').removeClass()
           for(var i = 1; i<= 3; i++){
               var number = 1 + Math.floor(Math.random() * 3);
               $('#div-'+i).addClass('clicked-'+number);
           }
       }, 1000);
   });
});