Reputation: 2693
I'm new to Twitter Bootstrap framework. I would like to open and close a div from a button. How to do that?
Thanks Uli
Upvotes: 3
Views: 10255
Reputation: 5589
This is covered explicitly in the bootstrap docs.
There is no JS needed (other than including the bootstrap JS.) Everything is done via data attributes.
<button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#demo">
simple collapsible
</button>
<div id="demo" class="collapse in"> collapse </div>
Here's a demo: http://jsfiddle.net/3UubF/
Upvotes: 10
Reputation: 74
Do you mean show and hide? If so, I'd just use jQuery. It's Bootstrap's js framework of choice. I'd do something like this...
<a class="btn" id="togglemydiv">My Button</a>
$('#togglemydiv').on('click', function() { $('#targetdiv').toggleClass('hide'); });
Upvotes: 0