JSFiddle - React, Tailwind, and code Playground
HTML
<div id="dialog">Some demo text here.</div>
<div>some other demo text</div>
CSS
#dialog {
height: 300px;
width: 300px;
border: 2px solid orange;
}
JavaScript
document.addEventListener("click", function (e) {
if (e.target.id != "dialog") {
document.getElementById("dialog").style.display = "none";
}
});