Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML data-toggle="collapse" only collapse if it isn't already

I want to collapse a div with a button if it is not collapsed already. I have a button:

<button data-toggle="collapse" data-target="#aim" ...></button>

and my div:

<div id="#aim" class="collapse"></div>

I works great but if the div is already open the button close it.

Is there a chance to get collapse it when it isn't already?

like image 288
Philip Scheer Avatar asked Mar 07 '14 12:03

Philip Scheer


3 Answers

My solution:

<button data-toggle="collapse" data-target="#aim" ...></button>

<div id="aim" class="collapse in"></div>

so when you use collapse in instead of collapse it only expands and do not minimize itselfs again when it already expanded.

like image 180
Philip Scheer Avatar answered Nov 15 '22 01:11

Philip Scheer


Remove the # from your <div id="#aim" class="collapse"> and it should work. More info about bootstrap's data-toggle attribute can be found here.

(Previous comment added as possible answer to help close this question).

like image 40
SaschaM78 Avatar answered Nov 15 '22 01:11

SaschaM78


Use Javascript with on click and hide().

like image 42
Pickaboo Avatar answered Nov 15 '22 00:11

Pickaboo