Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Collapse loads collapsed on page load

the title pretty much covers the problem I'm having.

I've a list on a website I'm developing and I have hidden things within collapsible elements.

The problem I have is that they are already collapsed on page load.

Does anyone have any idea on how to fix this?

Thanks.

like image 926
Daniel W Avatar asked Jun 03 '14 14:06

Daniel W


People also ask

How does collapse work in Bootstrap?

How it works. The collapse JavaScript plugin is used to show and hide content. Buttons or anchors are used as triggers that are mapped to specific elements you toggle. Collapsing an element will animate the height from it's current value to 0 .

How do I keep my Bootstrap collapse Open?

Just add data-toggle="collapse" and a data-target to element, to automatically assign control of a collapsible element. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element. If you'd like it to default open, add the additional class in .

How do I stop a Bootstrap collapse?

To control (show/hide) the collapsible content, add the data-toggle="collapse" attribute to an <a> or a <button> element. Then add the data-target="#id" attribute to connect the button with the collapsible content (<div id="demo">).

How do you collapse an accordion by default?

This can be done by setting the 'active' property of jQuery Accordion as false.


3 Answers

Thanks for your comment Rob.

Figured it after looking through the HTML, I need to use collapse but all but one were using collapse in (or collapse show in bootstrap 4).

Problem sorted :)

Load collapsed on page load :

<div id="collapseOne" class="panel-collapse collapse in">

Load hidden until clicked :

<div id="collapseOne" class="panel-collapse collapse">
like image 99
Daniel W Avatar answered Sep 30 '22 19:09

Daniel W


As of bootstrap 4.2.1 if we want to show the collapsed content on load:

use collapse show class to the div or any element you want to show.

check the docs Bootstrap Collapse

like image 41
ImFarhad Avatar answered Sep 30 '22 18:09

ImFarhad


Bootstrap documentation says this:

The collapse plugin utilizes a few classes to handle the heavy lifting:

.collapse hides the content

.collapse.in shows the content

.collapsing is added when the transition starts, and removed when it finishes

Edit your HTML accordingly (use collapse.in instead of collapse)

like image 37
Robert Levy Avatar answered Sep 30 '22 19:09

Robert Levy