Reputation: 7953
i am trying to select value for the selected button like the following :
html code :
<div class="span3">
<div>DEBIT/CREDIT</div>
<div class="btn-group" data-toggle="buttons-radio" id="investadjust-debitcredit-button">
<button name="debitCredit" type="button" id="credit-button" class="btn active" value="CREDIT" >CREDIT</button>
<button name="debitCredit" type="button" id="debi-button" class="btn" value="DEBIT" >DEBIT</button>
</div>
</div>
javascript code :
$("#investadjust-debitcredit-button>.active").val()
but i get only empty
when i printed the above line after selecting one button.
what could be the reason.
Upvotes: 3
Views: 115
Reputation: 73
As neo said you need to place your code in document ready function and use the class name of the button without spaces or you can add underscore between the words as well like this:
<button name="debitCredit" type="button" id="credit-button" class="btn_active" value="CREDIT" >CREDIT</button>
So, the code goes like:
$(document).ready(function(){
alert("value "+$("#investadjust-debitcredit-button>.btn_active").val());
});
Good Luck!
Upvotes: 1
Reputation: 1063
you need to place your code in
$(document).ready(function(){
// your jquery code
});
Upvotes: 2