JSFiddle - React, Tailwind, and code Playground

HTML

<div id="div"></div>

CSS

div {
    background: red;
    height: 200px;
    width: 200px;
}

JavaScript

div.addEventListener("click", function(e){
    e.stopPropagation();
});

document.documentElement.addEventListener("click",function(){
    alert("Has hecho click fuera del div.");
});