JSFiddle - React, Tailwind, and code Playground
HTML
<div class="rect"></div>
<div class="rect"></div>
CSS
.rect{
width:100px;
height:100px;
background:red;
float:left;
margin-left:20px;
font-size:20px;
}
JavaScript
$('html').click(function(){
$('.rect').removeClass('active')
.css('background','red');
});
$('.rect').click(function(event){
if($(this).hasClass('active')){
$(this).removeClass('active')
.css('background','red');
} else {
$(this).addClass('active')
.css('background','blue');
}
event.stopPropagation();
});