jquery - Accordion active don't work on first load -
when loads first time trying active first div makes div active except of first. here on jsfiddle.
$(".accordion > span").click(function(){ $('.accordion > span').removeclass('active'); $(this).addclass('active'); if(false == $(this).next().is(':visible')) { $('.accordion > div').slideup(300); } $(this).next().slidetoggle(300); }); var animationisoff = $.fx.off; $.fx.off = true; $('.accordion > span:eq(0)').click() $.fx.off = animationisoff; here html
<div class="accordion"> <span>accor 1</span> <div> content here </div> </div> <div class="accordion"> <span>accor 2</span> <div> content here </div> </div> <div class="accordion"> <span>accor 2</span> <div> content here </div> </div> any highly appreciated.
you close.
all need add active class first span.
$('.accordion > span:eq(0)').addclass('active'); or
you can hide other div.
$('.accordion > span:not(:eq(0))').next('div').css('display','none');
Comments
Post a Comment