JSFiddle - React, Tailwind, and code Playground
HTML
<div id="trocaCor" class="vermelho"></div>
<div id="trocaCor" class="vermelho"></div>
<div id="trocaCor" class="vermelho"></div>
<div id="trocaCor" class="vermelho"></div>
CSS
#trocaCor{
margin:50px;
height:100px;
}
.vermelho{
background:red;
}
.verde{
background:green;
}
JavaScript
$('#trocaCor').click(function(){
var $this = $(this);
if($this.hasClass('vermelho')){
$(this).switchClass('vermelho','verde', 500);
}else{
$(this).switchClass('verde','vermelho', 500);
}
})