JSFiddle - React, Tailwind, and code Playground

by techiedelight

HTML

<div id="container">
  <label>Enter your name:</label>
  <input type="text">
  <button id="submit">Submit</button>
</div>

CSS

div {
  border: 1px solid grey;
  padding: 5px;
}

JavaScript

document.addEventListener('mouseup', function(e) {
  var container = document.getElementById('container');
  if (!container.contains(e.target)) {
    container.style.display = 'none';
  }
});