title: Trigger event if click outside selector
body: <p>I'm trying to click somewhere other than the button, hide the element, but I do not get it, I have no idea how to do it.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function(){
    
    $(document).on('click','#foo',function(){
      let div = $('#bar');
      if( div.css('display') === 'none' ){
        div.show();
      }
      
      else{
        div.hide();
      }
    });
  
  })</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#foo{
    min-width: 35%;
  }
  
  #bar{
    max-width: 35%;
    min-height: 100px;
    background-color: aliceblue;
    border: 1px solid blue;
    border-radius: 5px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;button id="foo"&gt;Toggle&lt;/button&gt;&lt;br&gt;&lt;br&gt;
  &lt;div id="bar"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I got an idea but it doesn´t work.</p>
  
  <pre><code>  $(document).on('click','html',function(e){
      if(e.eventTarget !== 'foo'){
        $('#bar').hide();
      }
    });
  </code></pre>
  
  <p>I got 2 issues, if the selector is html, the page will not answer, and the code in, is just to show what I'm trying to get.</p>