JSFiddle - React, Tailwind, and code Playground
HTML
<div id="mywidget">My Widget</div>
CSS
#mywidget {
border: 5px solid red;
height: 400px;
width: 200px;
}
JavaScript
$(document).on('click', function (event) {
var $element = $(event.target);
if ($element.attr('id') === 'mywidget') {
// do nothing
} else {
alert('you have clicked outside the widget!');
}
});