/ Published in: jQuery
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$("fieldset").each(function (){ if($(this).attr('class')!='active'){ $("div.expandContent", this).hide(); } }); $(".expandChild").click(function (e){ e.preventDefault(); if(!$(this).hasClass('expandChildActive')){ $("div.expandContent").slideUp(); $(this).next().next().height($(this).next().next().height()); //Fix for slide jumping position $(this).next().next().slideToggle(); $('button.expandChild').removeClass('expandChildActive'); $(this).addClass('expandChildActive'); } else { $(this).next().next().slideToggle(); $(this).removeClass('expandChildActive'); } }); <fieldset class="active"> <h1>Title</h1> <button class="suspendacc"></button> <button class="expandChild expandChildActive"></button> <div class="clear"></div> <div class="expandContent"> </div> </fieldset> <fieldset class="active"> <h1>Title 2</h1> <button class="suspendacc"></button> <button class="expandChild"></button> <div class="clear"></div> <div class="expandContent"> </div> </fieldset>