Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Collapse not Collapsing

I am trying to create a collapsable component using Bootstrap. My code is this

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">  <script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>    <div class="panel-group" id="accordion">    <div class="panel panel-default">      <div class="panel-heading">        <h4 class="panel-title">          <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">        Collapsible Group Item #1      </a>        </h4>      </div>      <div id="collapseOne" class="panel-collapse collapse in">        <div class="panel-body">          Anim pariatur cliche reprehenderit        </div>      </div>    </div>  </div>

The "Collapsible Group Item #1" when clicked should collapse the items in class "panel-body" but it doesn't there is no effect of click. I copied this code directly from Bootstrap documentation still it does not work. Can anyone figure out what is the problem?

like image 626
poshanniraula Avatar asked Apr 09 '14 07:04

poshanniraula


People also ask

Why is my Bootstrap toggle not working?

The Best Answer isYou need the jQuery and Boostrap Javascript files included in your HTML page for the toggle to work. (Make sure you include jQuery before Bootstrap.)

How do I collapse in Bootstrap?

Just add data-toggle="collapse" and a data-target to the element to automatically assign control of one or more collapsible elements. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element.

How do you make an accordion not collapse?

Your child Accordion items aren't collapsing because you're setting data-parent to their own individual boxes. If you apply an ID of accordion-sub to . panel-body and then change your data-parent to match you'll achieve something functional. I followed your example and it works a treat!

What is Bootstrap 4 collapse?

collapse class indicates a collapsible element (a <div> in our example); this is the content that will be shown or hidden with a click of a button. To control (show/hide) the collapsible content, add the data-toggle="collapse" attribute to an <a> or a <button> element.


1 Answers

jQuery is required (if you're using Bootstrap 3 or 4) ;-)

<html> <head>     <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">     <!-- THIS LINE -->     <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>     <script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> </head> <body>  <div class="panel-group" id="accordion">     <div class="panel panel-default">         <div class="panel-heading">             <h4 class="panel-title">                 <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">                     Collapsible Group Item #1                 </a>             </h4>         </div>         <div id="collapseOne" class="panel-collapse collapse in">             <div class="panel-body">                 Anim pariatur cliche reprehenderit             </div>         </div>     </div> </div>  </body> </html>
like image 181
MaiKaY Avatar answered Oct 07 '22 18:10

MaiKaY