how does $(e.target).parents work?

how does $(e.target).parents work?

I've got a fixed-position div (.panel) that I am hiding/showing based on a click event of a trigger (.trigger).  When the (.panel) div is visible, I want the contents of the div to be clickable and the trigger (.trigger) to toggle the visibility.  No problem there... works great.  As an added usability feature, I want to close the (.panel) div if the user clicks either the trigger (.trigger) or anywhere outside of the (.panel) div itself (any where else on the page). 

This is the code that I am implementing:
  1. $(".trigger").click(function(e) {
      e.preventDefault();
      $(".panel").toggle("fast");
      $(this).toggleClass("active");
    });
    $(".trigger").mouseup(function() {
      return false
    });






This is how I am attempting to close the div when the user clicks outside of it:
  1. $(document).mouseup(function(e) {
      if ($(e.target).parents(".panel").length == 0) {
        $(".trigger").removeClass("active");
        $(".panel").hide("fast");
      }
    });




This sort of works... but now when I click anywhere on the page (regardless of whether or not the .panel div is visible, I get a quick show/hide of the .panel div... meaning any click on the page shows the div and then quickly hides it.  Does anyone see anything wrong with the above code?