JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myDiv"><p>
element inside
</p></div>
CSS
#myDiv {
background: #ff0000;
width: 25vw;
height: 25vh;
}
JavaScript
$(function() {
$("body").click(function(e) {
if (e.target.id == "myDiv" || $(e.target).parents("#myDiv").length) {
alert("Inside div"+$(e.target).parents("#myDiv"));
} else {
alert("Outside div");
}
});
})