Reputation: 611
when it loads first time i am trying to active first div but it makes all div active except of first. here it is 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 is 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 help will be highly appreciated.
Upvotes: 1
Views: 89
Reputation: 27364
You are very close.
All you need to do is add active
class for first span.
$('.accordion > span:eq(0)').addClass('active');
OR
You can hide
other div
.
$('.accordion > span:not(:eq(0))').next('div').css('display','none');
Upvotes: 1