Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Accordion Panel/Collapse

My bootstrap accordian is acting temperamental! I have created three panels displayed in a column grid, but the 2nd and 3rd collapse menu closes the wrong menu (e.g. clicking/opening menu2 then clicking/opening menu3 will close menu2 before opening menu3).

Any idea why?

Code here:

        <div class="row">
            <div class="col-sm-6 col-md-4">
                <div class="panel-group">
                    <div class="panel panel-default">
                        <a class="panel-default" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
                        <div class="panel-heading">
                            <h4 class="panel-title">
                            My Story
                            </h4>
                        </div>
                        </a>
                        <div id="collapseOne" class="panel-collapse collapse">
                            <div class="panel-body">
                            Content
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6 col-md-4">
                <div class="panel-group" id="accordion">
                    <div class="panel panel-default">
                        <a class="panel-default" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
                        <div class="panel-heading">
                            <h4 class="panel-title">
                            My Skills
                            </h4>
                        </div>
                        </a>                            
                        <div id="collapseTwo" class="panel-collapse collapse in">
                            <div class="panel-body">
                            Content
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6 col-md-4">
                <div class="panel-group" id="accordion">
                    <div class="panel panel-default">
                        <a class="panel-default" data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
                        <div class="panel-heading">
                            <h4 class="panel-title">
                            My Ambition
                            </h4>
                        </div>
                        </a>                            
                        <div id="collapseThree" class="panel-collapse collapse">
                            <div class="panel-body">
                            content
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
like image 676
tom1bomb Avatar asked Jan 27 '14 21:01

tom1bomb


1 Answers

You need to number the accordion i.e. accordion1 accordion2 accordion3

<div class="row">
    <div class="col-sm-6 col-md-4">
        <div class="panel-group">
            <div class="panel panel-default">
                <a class="panel-default" data-toggle="collapse" data-parent="#accordion1" href="#collapseOne">
                <div class="panel-heading">
                    <h4 class="panel-title">
                    My Story
                    </h4>
                </div>
                </a>
                <div id="collapseOne" class="panel-collapse collapse">
                    <div class="panel-body">
                    Content
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-sm-6 col-md-4">
        <div class="panel-group" id="accordion">
            <div class="panel panel-default">
                <a class="panel-default" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
                <div class="panel-heading">
                    <h4 class="panel-title">
                    My Skills
                    </h4>
                </div>
                </a>                            
                <div id="collapseTwo" class="panel-collapse collapse in">
                    <div class="panel-body">
                    Content
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-sm-6 col-md-4">
        <div class="panel-group" id="accordion">
            <div class="panel panel-default">
                <a class="panel-default" data-toggle="collapse" data-parent="#accordion3" href="#collapseThree">
                <div class="panel-heading">
                    <h4 class="panel-title">
                    My Ambition
                    </h4>
                </div>
                </a>                            
                <div id="collapseThree" class="panel-collapse collapse">
                    <div class="panel-body">
                    content
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
like image 74
Zeeba Avatar answered Sep 29 '22 16:09

Zeeba