Reputation: 3129
I have the panel closing on a button click but when I click the button again, the panel won't open.
I have checked to make sure that I wasn't missing any closing tags and found that everything was fine.
Not sure what I missed.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#myPanel" aria-expanded="false" aria-controls="myPanel">
Collapse
</button>
<div id="VIDContactInfoWrapper" style="border:1px solid black;">
<div class="panel panel-default" style="height:inherit;">
<div class="panel-heading" style="padding: 5px 5px !important">Information</div>
<div class="panel-body" id="myPanel" style="padding-top:0;padding-bottom:0;height:300px; background-color:hotpink;">
<div class="row">
<div class="col-md-12">
<div class="row">
<div id="VIContactInfo" class="col-md-6" style="background: white;"></div>
<div id="VIAddressInfo" class="col-md-6" style="background: white;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
Upvotes: 0
Views: 38
Reputation: 13666
The code you provided is working as expected. The problem is that you're defining the height of the panel-body
element with inline styling, which is getting overwritten when you use the Bootstrap toggle. To resolve this, just allow the content within panel-body
to define the height, or define the height in external CSS instead:
.panel-body {
padding-top:0;
padding-bottom:0;
height:300px;
background-color:hotpink;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#myPanel" aria-expanded="false" aria-controls="myPanel">
Collapse
</button>
<div id="VIDContactInfoWrapper" style="border:1px solid black;">
<div class="panel panel-default" style="height:inherit;">
<div class="panel-heading" style="padding: 5px 5px !important">Information</div>
<div class="panel-body" id="myPanel">
<div class="row">
<div class="col-md-12">
<div class="row">
<div id="VIContactInfo" class="col-md-6" style="background: white;"></div>
<div id="VIAddressInfo" class="col-md-6" style="background: white;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
Upvotes: 0
Reputation: 15857
You actually have to wrap your panel-body in the collapsible div. https://getbootstrap.com/docs/3.3/javascript/#collapse
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#myPanel" aria-expanded="false" aria-controls="myPanel">
Collapse
</button>
<div id="VIDContactInfoWrapper" style="border:1px solid black;">
<div class="panel panel-default" style="height:inherit;">
<div class="panel-heading" style="padding: 5px 5px !important">Information</div>
<div id="myPanel" class="panel-collapse collapse in">
<div class="panel-body" style="padding-top:0;padding-bottom:0;height:300px; background-color:hotpink;">
<div class="row">
<div class="col-md-12">
<div class="row">
<div id="VIContactInfo" class="col-md-6" style="background: white;"></div>
<div id="VIAddressInfo" class="col-md-6" style="background: white;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Upvotes: 1