views:

318

answers:

3

Hi,

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!

A: 

$("#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.)

Ed Woodcock
that just causes the accordion to open both segments! am i missing something??<script type="text/javascript">$("#accordion").accordion({ active: 2, event: "mouseover" }); </script>
Bomski
That's odd, accordions aren't meant to be able to open more than one item at once!
Ed Woodcock
i know... it doesn't work at all now... there must be something wrong with the javascript;
Bomski
update works, but closes all accordions....! modified index to 0 and resolved.... many thanks!
Bomski
good stuff, glad to help
Ed Woodcock
Isn't the update really slow? As in, you are attaching the accordion the first time and then running the whole thing again to activate an index.Also, Darmen's answer will be a much faster approach after you just create it, i.e: `$('#accordion').accordion({ event: "mouseover"}).activate(2)`
Adhip Gupta
That would be slower than just calling `activate` method.
Darmen
point taken: will edit.
Ed Woodcock
+2  A: 

Try

$("#accordion").activate(index);
Darmen
A: 

Does the following work?

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

});
Adhip Gupta