title: jQuery body click problem
body: <p>I have a div I want to hide when clicking outside it. </p>
  
  <p>It almost works, except the button class is only changing once every two times. </p>
  
  <p>I click on the button, the active button class is added and the dropdown slides down, I click somewhere outside the dropdown, it slides up and the button class returns to it's original state. BUT, when I repeat this, the button class 'isActive' is not added.</p>
  
  <p>Here's the function:</p>
  
  <pre><code>function toggleSelectGroupList(){
      $('#groupListSortby').slideToggle(30);
  
  
      $('body').click(function(){  
          $('#groupListSortby').click(function(e) {    e.stopPropagation();   })
          $('#groupListSortby').hide(); 
          $('.sortFriends .btngrey .gfx').toggleClass('isActive');
          $('.sortFriends .btngrey a').toggleClass('isActive');
      }); 
  }
  </code></pre>
  
  <p>Markup:</p>
  
  <pre><code>&lt;div class="sortFriends"&gt;
  
  &lt;div class="btngrey"&gt;
      &lt;span class="gfx"&gt;&lt;/span&gt;
      &lt;a onClick="toggleSelectGroupList()"&gt;All friends&lt;/a&gt;
  &lt;/div&gt;
  
  &lt;div class="dropdownList" id="groupListSortby"&gt;
      &lt;ul&gt;
          &lt;li class="isActive"&gt;
              &lt;span class="gfx"&gt;&lt;/span&gt;
              &lt;a href="#"&gt;All friends&lt;/a&gt;
          &lt;/li&gt;
          &lt;li&gt;
              &lt;a href="#"&gt;Recently added&lt;/a&gt;
          &lt;/li&gt;
          &lt;li class="last"&gt;
              &lt;a href="#"&gt;The Railers&lt;/a&gt;
          &lt;/li&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>