Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the value of selected button in twitter bootstrap button group

If I haev a radio button group in bootstrap like the following :

<div class="btn-group" data-toggle="buttons-radio">
        <button class="btn">1</button>
        <button class="btn">2</button>
        <button class="btn">3</button>
        <button class="btn">4</button>
</div>

How can I get/ set the selected value ?

like image 909
Adham Avatar asked Jun 08 '12 00:06

Adham


People also ask

What is the difference between button and button Group in bootstrap?

“Button Groups” in Bootstrap is a class of name “btn-group” which is used to create series of buttons in groups (without spaces) vertically or horizontally. This is the basic syntax of the button group class where each button has its own class of “btn”.

Which class is used to group buttons together in bootstrap?

Place a .btn-group within another .btn-group when you want dropdown menus mixed with a series of buttons.


1 Answers

To set the active element, add the class active to whichever button you want selected (and deselect the rest).

$('.btn-group > .btn').removeClass('active')    // Remove any existing active classes
$('.btn-group > .btn').eq(0).addClass('active') // Add the class to the nth element

To get the html/text content of the currently active button, try something like this:

$('.btn-group > .btn.active').html()
like image 114
Tyler Johnson Avatar answered Nov 08 '22 20:11

Tyler Johnson