javascript - jQueryUI - Accordion - Setting Active using ID - Stack Overflow

I've checked a number of sites trying to figure this out. However, I have had no luck and figured

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.

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.

Share Improve this question edited Mar 4, 2014 at 15:20 Spokey 11k2 gold badges31 silver badges44 bronze badges asked Mar 4, 2014 at 15:03 ZGold92ZGold92 231 silver badge3 bronze badges 3
  • I don't get it... what do you want to set active? – Spokey Commented Mar 4, 2014 at 15:07
  • Looks like you need to set a number, not a string: $( ".selector" ).accordion({ active: 2 }); – ravb79 Commented Mar 4, 2014 at 15:08
  • but it works.. jsfiddle/Spokey/uKzpp what version are you using? – Spokey Commented Mar 4, 2014 at 15:13
Add a ment  | 

1 Answer 1

Reset to default 5

Set active based on the h3 index:

active: $('#accordion h3').index($('.content3'))

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745433124a4627484.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信