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'); 

http://jsfiddle.net/ym2e3/2/

or

you can hide other div.

$('.accordion > span:not(:eq(0))').next('div').css('display','none'); 

http://jsfiddle.net/ym2e3/9/


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -