Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get bootstrap buttons to show active state?

I'm having a problem with a set of radio buttons.

<div class="btn-group control-buttons" data-toggle="buttons-radio">
    <button type="button" class="btn">One</button>
    <button type="button" class="btn">Two</button>
    <button type="button" class="btn">Three</button>
</div>

See here: http://jsfiddle.net/dhbenson/LM9uW/

When the buttons are clicked, they don't ever stay depressed (i.e. none ever appear to be "active").

Does anyone know why not? What else do I need to do to make these buttons work properly?

EDIT

Ah, I see. I forgot to include the bootstrap js code.

This fiddle works: http://jsfiddle.net/dhbenson/qNeSS/

like image 839
dB' Avatar asked Dec 24 '12 02:12

dB'


People also ask

How do I make an active state button?

To set the active state for Bootstrap Buttons, use the . active class.

How can make button Unclickable in Bootstrap?

Active/Disabled Buttons The class . active makes a button appear pressed, and the disabled attribute makes a button unclickable. Note that <a> elements do not support the disabled attribute and must therefore use the . disabled class to make it visually appear disabled.


2 Answers

You need the bootstrap javascript for that functionality.

Add this to your HTML head:

<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
like image 187
Amir T Avatar answered Nov 03 '22 06:11

Amir T


Try this code:

<div class="btn-group" data-toggle="buttons-checkbox">
    <button type="button" class="btn">Left</button>
    <button type="button" class="btn">Middle</button>
    <button type="button" class="btn">Right</button>
</div>

and add one file i.e. bootstrap-button.js

like image 42
Rupesh Nerkar Avatar answered Nov 03 '22 05:11

Rupesh Nerkar