JSFiddle - React, Tailwind, and code Playground
HTML
<div class="test">
<span>Hello world</span>
</div>
CSS
.test {
background: #AAA;
padding: 10px;
}
JavaScript
var test = document.querySelector('.test');
function removeTest(e) {
if(!e.target.matches('.test, .test *')) {
test.remove();
this.removeEventListener('click', removeTest);
}
};
window.addEventListener('click', removeTest);