title: How to identify when a click is made outside the popup window?
body: <p>I have a popup window which disappears on click inside, but my purpose is to make it disappear on click outside.</p>
  
  <p>At the moment the popup works fine but it disappears whenever I click inside the window. When I click outside the window, it stays. How do I make it work the oppersite way around?</p>
  
  <p>Code as:</p>
  
  <pre><code>function deselect(e) {
    $('.pop').slideFadeToggle(function() {
      e.removeClass('selected');
    });    
  }
  
  $(function() {
    $('.invite_room_btn').on('click', function() {
      if($(this).hasClass('selected')) {
        deselect($(this));               
      } else {
        $(this).addClass('selected');
        $('.pop').slideFadeToggle();
      }
      return false;
    });
  
    $('.close').on('click', function() {
      deselect($('.invite_room_btn'));
      return false;
    });
  });
  
  $.fn.slideFadeToggle = function(easing, callback) {
    return this.animate({ opacity: 'toggle', height: 'toggle' }, 'fast', easing, callback);
  };
  </code></pre>
  
  <p>And HTML is:</p>
  
  <pre><code>&lt;span class="invite_room_btn"&gt;
              &lt;div class="messagepop pop"&gt;
              &lt;/div&gt;
  &lt;/span&gt;
  </code></pre>
  
  <p>Thanks!</p>