title: jQuery click outside to close a filter
body: <p>I have a Side Filter, where a User can fill out some information and filter a Webpage.</p>
  
  <p>I want this menu to appear when clicking a button and disappear when I click outside of it. This is what I currently have to make the Filter disappear once the user clicks outside of it:</p>
  
  <pre><code>$(window).click(function(e) {
      if ((!$(e.target).hasClass("filterOverlay")) &amp;&amp; (!$(e.target).hasClass("toggleFilterButton"))) {
  
          $('.filterOverlay').hide();
          $('.darkBackground').hide();
      }
  });
  </code></pre>
  
  <p>This works. However only if the Filter is empty. Because the fun thing is, when I add an Input-Field and click it. Of course Jquery doesn't recognize it as being the Filter and closes it.</p>
  
  <p>What's the best way to go with such a thing? All I find is the solution above, but as pointed out, this doesn't really fit.</p>