Bomski Bomski - 6 months ago 25
Javascript Question

jQuery Accordion - open specific section on pageload

I have a rather basic implementation of a jQuery Accordion on a page (using 1.3.2, jQuery UI Core 1.72 and jQuery UI Accordion 1.7.2), and I wish to open the 2nd section when the page loads. i've tried numerous methods but nothing seems to work...

HEAD SCRIPT:

<script type="text/javascript"> $(function() {
$("#accordion").accordion({
event: "mouseover"
});

});




BODY ACCORDION:

<div id="accordion">
<h3><a href="#">Headline 001</a></h3>
<div>
<ul>
<li><a href="#1">Link 001</a></li>
<li><a href="#2">Link 002</a></li>
</ul>
</div>
<h3><a href="#">Headline 002</a></h3>
<div>
<ul>
<li><a href="#3">Link 003</a></li>
<li><a href="#4">Link 004</a></li>
</ul>
</div>




Any help would be greatly appreciated!

Answer
$("#accordion").accordion({ active: 2, event: "mouseover" });

Should do the trick!

UPDATE

if that doesn't work, try

$("#accordion").accordion({  event: "mouseover" }).activate(2);

(N.B. this is updated to be a bit faster, thanks for the comments. To be honest, it should work with the 'active: 2' parameter, don't know why it didn't.)