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?
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
).