JSFiddle - React, Tailwind, and code Playground

by Marco Abate

HTML

<div class="wrapper">
    <div class="test">
        Testo di test
        <button class="btn btn-danger">Button</button>
    </div>
</div>

CSS

.wrapper {
    padding: 25%;    
}

.test {
    padding: 25px;
    background: lightskyblue;
    position: relative;
}

.test.on {
    background: gray;
    color: white;
}

.test .btn {
    position: absolute;
    right: 15px;
    top: 20px;
    outline: inherit;
}

JavaScript

var docClick = $('body').on('click tap', document, function(e) {
    var selectedTarget = e.target;
    console.log(selectedTarget);
    console.log($('.wrapper'));
    if(selectedTarget == $('.wrapper')) {
        $('.test').toggleClass('on');
    }
    
})