javascript - Button value is empty when use jquery selector -


i trying select value selected button 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 empty when printed above line after selecting 1 button.

what reason.

as neo said need place code in document ready function , use class name of button without spaces or can add underscore between words this:

<button name="debitcredit" type="button" id="credit-button" class="btn_active" value="credit" >credit</button> 

so, code goes like:

$(document).ready(function(){    alert("value "+$("#investadjust-debitcredit-button>.btn_active").val()); }); 

good luck!


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -