Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap accordion only auto-collapsing one panel

I've been scratching my head on this for the past 2 hours. I have an accordion with two panels. I want the first panel to be expanded by default. When the collapsed panel's header is clicked, I want that panel to expand and the other to collapse. It only works in certain situations for the second panel.

Here is a JSFiddle.

Here is my markup:

<div id="proposalAccordian" class="panel-group">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#proposalAccordian" href="#collapseContact">Contact</a>
            </h4>
        </div>
        <div id="collapseContact" class="panel-collapse collapse in">
            <div class="panel-body">
                @Html.Partial("_ContactPanel")
            </div>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#proposalAccordion" href="#collapseProposal">Proposal</a>
            </h4>
        </div>
        <div id="collapseProposal" class="panel-collapse collapse">
            <div class="panel-body">
                @Html.Partial("_ProposalPanel")
            </div>
        </div>
    </div>
</div>

I'm using Bootstrap v3.1.1 and jQuery v1.10.4.

like image 284
im1dermike Avatar asked Dec 20 '22 14:12

im1dermike


1 Answers

You need to add data-parent="#proposalAccordian"

<a data-toggle="collapse" data-parent="#proposalAccordian"  href="#collapseProposal">Proposal</a>

See fiddle: http://jsfiddle.net/nicos/JKqGc/

like image 55
Panoply Avatar answered Mar 05 '23 09:03

Panoply