javascript - jQuery nested accordion - disable auto open - Stack Overflow

I am trying to make it so that the accordion (#subAccordion1) within the parent (#accordion) is closed

I am trying to make it so that the accordion (#subAccordion1) within the parent (#accordion) is closed by default (note: there is only one subAccordion).

I am having some trouble doing this..

Here is my jQuery that I have tried:

$(function() {
    $("#accordion, #subAccordion1").accordion(function() {
        autoHeight: false
        active: false
        collapsible: true
    });
});

And my HTML:

<div id = "accordion">
     <h1>Accordion1:</h1>
     <div>
         <p>Blah</p>

         <div id = "subAccordion1">
             <h1>Accordion1.1</h1>
             <div>
                 <p> BLAH BLAH BLAH</p>
             </div>
         </div>
      <h1>Accordion2:</h1>
      <div>
           <p>Blah</p>
      </div>
</div>

The 2 outer accordions (1 and 2) are working as intended just the inner one (1.1) is automatically expanded!

Thanks for any help

I am trying to make it so that the accordion (#subAccordion1) within the parent (#accordion) is closed by default (note: there is only one subAccordion).

I am having some trouble doing this..

Here is my jQuery that I have tried:

$(function() {
    $("#accordion, #subAccordion1").accordion(function() {
        autoHeight: false
        active: false
        collapsible: true
    });
});

And my HTML:

<div id = "accordion">
     <h1>Accordion1:</h1>
     <div>
         <p>Blah</p>

         <div id = "subAccordion1">
             <h1>Accordion1.1</h1>
             <div>
                 <p> BLAH BLAH BLAH</p>
             </div>
         </div>
      <h1>Accordion2:</h1>
      <div>
           <p>Blah</p>
      </div>
</div>

The 2 outer accordions (1 and 2) are working as intended just the inner one (1.1) is automatically expanded!

Thanks for any help

Share Improve this question edited Apr 3, 2013 at 20:13 dfsq 193k26 gold badges242 silver badges259 bronze badges asked Apr 3, 2013 at 20:11 New_programmerNew_programmer 2853 gold badges7 silver badges16 bronze badges 2
  • Do you have jsfiddle link? – Khanh Tran Commented Apr 3, 2013 at 20:15
  • may we assume your missing </div> is a typo? – Mark Schultheiss Commented Apr 3, 2013 at 20:23
Add a ment  | 

2 Answers 2

Reset to default 5

Fix your HTML first (missing closing div):

<div id = "accordion">
     <h1>Accordion1:</h1>
     <div>
         <p>Blah</p>
         <div id = "subAccordion1">
             <h1>Accordion1.1</h1>
             <div>
                 <p> BLAH BLAH BLAH</p>
             </div>
         </div>
      </div>
      <h1>Accordion2:</h1>
      <div>
           <p>Blah</p>
      </div>
</div> 

JavaScript

$(function() {
  // init parent accordion
  $("#accordion").accordion( { heightStyle: "content" });

  // init sub accordion via #id selector with options object
  $("#subAccordion1").accordion({
                autoHeight: false,
                active: false,
                collapsible: true,
                heightStyle: "content"
   });
});

Try

$("#accordion, #subAccordion1").accordion({

instead of

$("#accordion, #subAccordion1").accordion(function() {

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

相关推荐

  • javascript - jQuery nested accordion - disable auto open - Stack Overflow

    I am trying to make it so that the accordion (#subAccordion1) within the parent (#accordion) is closed

    12小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信