Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding button after collapse is toggled in bootstrap

Given the following code from the bootstrap website for the collapse functionality:

<a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
  Link with href
</a> 
<div class="collapse" id="collapseExample">
  <div class="well">
    ...
  </div>
</div>

What I would like to do is hide the link, that invokes the collapse functionality once its open, does anyone know of a way I can do this without adding additional Js?

like image 518
shenku Avatar asked Jan 21 '15 01:01

shenku


3 Answers

I used this to hide the button after it was clicked:

HTML (just added a class "hide-me"):

<button class="btn btn-default hide-me" data-toggle="collapse" data-target="#search" id="search-display">My Button</button>

CSS:

.hide-me[aria-expanded="true"] {display: none;}
like image 125
createscape Avatar answered Oct 19 '22 15:10

createscape


This is what I was really looking for', without any CSS or JavaScript of my own, simply leveraging Bootstrap:

<a class="btn btn-primary hook in" data-toggle="collapse" href=".hook" aria-expanded="false" aria-controls="collapseExample">
  Link with href
</a> 
<div class="collapse hook">
  <div class="well">
    ...
  </div>
</div>

Heres the fiddle:

http://jsfiddle.net/hptrpaxh/1/

like image 44
shenku Avatar answered Oct 19 '22 15:10

shenku


Add this:

$('.btn').toggle();

I recommend you add an additional class to this button or give it an id to distinguish it from other buttons.

like image 1
trs Avatar answered Oct 19 '22 17:10

trs