jQuery toggle open/close modify existing code -
i'm working piece of code, works, toggles divs open. however, how can modify 1 div can have "open" class @ time? right can toggle divs open.. i'd 1 div can toggled open @ given time. click div, other toggles closed.
any help/direction much appreciated!
thank you!
$('body').on('click','.toggle h3 a', function(){ if(!$(this).parents('.toggles').hasclass('accordion')) { $(this).parents('.toggle').find('> div').slidetoggle(300); $(this).parents('.toggle').toggleclass('open'); //switch icon if( $(this).parents('.toggle').hasclass('open') ){ $(this).find('i').attr('class','icon-minus-sign'); } else { $(this).find('i').attr('class','icon-plus-sign'); } if($(this).parents('.toggle').find('> div .iframe-embed').length > 0 && $(this).parents('.toggle').find('> div .iframe-embed iframe').height() == '0') responsivevideoiframes(); homecoming false; } });
check out http://jqueryui.com/accordion/.
since you're using jquery check out premade one.
jquery toggle accordion
No comments:
Post a Comment