クリックイベントに問題があります。イベント(クリック)で別の要素をクリックすると、他の場所のクリックのようにカウントされません。アクティブな要素が 1 つ必要か、または何も必要ありません。
デモ: http://jsfiddle.net/WP4RH/
コード:
$('span').click(function(){
var $this = $(this);
if($this.hasClass('active')){
$this.removeClass('active')}
else $this.addClass('active');
$('div').click(function(){
if (!$this.has(this).length) {
$this.removeClass('active');
}
});
return false;
});