title: closing a div while click anywhere outside that div
body: <p>I am trying to create a jquery navigation bar. So when I click on <code>div</code> main, a new <code>div</code> will slide down and I want to add an option to close the window if we click anywhere outside the newly opened window. This is the code that I have used but it is not working.</p>
  
  <p>The newly opened <code>div</code> doesn't close when I click anywhere outside it.</p>
  
  <pre><code>var $s = $("#main");    
  $(document).ready(function () 
  {
    $(document.body).click(function()
    {
     $('ul.the_menu').slideToggle('medium');
     if (!$s.has(this).length) 
     {
        $s.hide();
     }    
   });
  });
  </code></pre>