/** * CHANGES * v.1.2 - Fixed bug when nested fieldsets are used. * v.1.1 - Changed $(this).parent().children().filter( ELEMENTS HERE) to $(this).parent().children().not('label'). Prevents you from having to guess what elements will be in the fieldset. * * This script may be used by anyone, but please link back to me. * * Copyright 2009. Michael Irwin */ $.fn.collapse = function() { return this.each(function() { $(this).find("legend:first").addClass('collapsible').click(function() { if ($(this).parent().hasClass('collapsed')) $(this).parent().removeClass('collapsed').addClass('collapsible'); $(this).removeClass('collapsed'); $(this).parent().children().not('legend:first').toggle("slow", function() { if ($(this).is(":visible")) $(this).parent().find("legend:first").addClass('collapsible'); else $(this).parent().addClass('collapsed').find("legend:first").addClass('collapsed'); }); }); }); };