title: How to hide div on outside click except one inside div through jquery
body: <p>This is just a sample code where i want hide div with id="img" on button click as well as outside div with with id="img"</p>
  
  <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div id="img"&gt;
  &lt;button id"imgoption"&gt; click here&lt;/butoon&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Here os the Script</p>
  
  <pre><code>&lt;script&gt;
   $(document).on('click', function(e) { // Hides the div by clicking any where in the screen
  
        if ( ! $(e.target).closest('#img').length ){
              $('#imgoption').hide();
          }
          if ( $(e.target).closest('#img').length ) {
                $("#imgoption").show();
          }
  
      });
  }):
  &lt;/script&gt;
  </code></pre>