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;
    }

.rect.active{
    background:blue;
}

JavaScript

$('html').click(function(){
        $('.rect').removeClass('active');
    });
    $('.rect').click(function(event){
        event.stopPropagation();
        $('.active').removeClass('active');
        $(this).addClass('active');
    });