Question

I've checked a number of sites trying to figure this out. However, I have had no luck and figured I would go ahead and make a post on here.

What I am trying to do is setting the Active Accordion depending on ID. Below, is what I am working with.

jQuery Code:

$(function () {
    $("#accordion").accordion({
        collapsible: true,
        header: "h3",
        active: 'h3.content3',
        heightStyle: "content"
    });
});

HTML:

<div id="accordion">
    <h3 class="content1">Content Title</h3>
    <div align="left">
        <p>Content for 1 Goes Here</p>
    </div>

    <h3 class="content2">Content Title</h3>
    <div align="left">
        <p>Content for 2 Goes Here</p>
    </div>

    <h3 class="content3">Content Title</h3>
    <div align="left">
        <p>Content for 3 Goes Here</p>
    </div>
</div>

I hope I explained it well enough, If not, Let me know. I'll try to help ya.

Was it helpful?

Solution

Set active based on the h3 index:

active: $('#accordion h3').index($('.content3'))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top