redflag237
redflag237

Reputation: 224

jQuery UI Accordion, default expanded

I'm using the jQueryUI Accordion plugin for site navigation. My page is rendered server-side, the current tab gets an attribute defaultactive=true. The markup is as following:

<ul class="accordion">
    <li>One</li>
    <li defaultactive="true">Two</li>
    <li>Three</li>
</ul>

I know this snippet to work as expected:

$("#accordion").accordion({ active: 2 });

What do I have to write to get the exact position (zero-based) of the li-element with defaultactive-attribute within the ul container?

Upvotes: 2

Views: 8212

Answers (2)

Rory McCrossan
Rory McCrossan

Reputation: 337560

You can use index() to achieve this:

$('.accordion li[defaultactive="true"]').index()

Example fiddle

Upvotes: 4

Fr&#233;d&#233;ric Hamidi
Fr&#233;d&#233;ric Hamidi

Reputation: 262919

Since all your <li> elements are siblings, you can use index():

$(".accordion").accordion({
    active: $(".accordion li[defaultactive=true]").index()
});

Note that according to your markup, you should use a class selector (.accordion), not an id selector (#accordion).

Upvotes: 4

Related Questions