I made the :active selector a subclass of .trigger , as @Christopher commented out and fixed the behavior of the .trigger X button to switch the class accordingly:
$('.trigger').click(function(event) { event.preventDefault(); var panel = $(this).next('.panel'); $('.panel').not(panel).hide(); panel.toggle("fast"); $('.trigger').not(this).removeClass('active');
Thus, it will remove the active class from the other X buttons and switch the current one on demand.
To close the fields when clicking .panel and .trigger , add this inside the DOM Ready handler:
$(document).click('click', function(e) { if (!$('.panel').is(':visible')) return; var targ = $(e.target); //doesn't close the boxes if target is .panel/.trigger or their descendant if (targ.closest('.panel').length || targ.is('.panel') || targ.closest('.trigger').length || targ.is('.trigger')) return; $('.panel').hide('fast'); $('.trigger').removeClass('active'); });
source share