Mac Ben Mac Ben - 7 months ago 22
Javascript Question

get bootstrap radio value from href buttons

Have a problem when trying to get values of radio with jquery.

Here my radio buttons:

<div class="input-group">
<div id="radioBtn" class="btn-group">
<a class="btn btn-warning radio-selector btn-sm active" data-toggle="happy" data-title="pub">Pub</a>
<a class="btn btn-warning radio-selector btn-sm notActive" data-toggle="happy" data-title="pri">Pri</a></a>
</div>
<input type="hidden" name="happy" id="happy">
</div>
<a id="add" class="btn btn-lg btn-primary">Add</a>


And here the javascript code to get the selected value:

$('#add').live("click",function() {
var getdata = $('#radioBtn .radio-selector:checked').data("title");
alert(getdata);
}


But all time i get undefined value ! any solution to get the
data-title
in the radio buttons ?

Answer

try this

$('#add').live("click",function() 
{
    var getdata = $('#radioBtn > a.active').data("title");
    alert(getdata);
}