Thursday, December 11, 2014

jQuery, selct and click radio button



For radio buttons in HTML
     <input type="radio" name="test" id="test1" />test1<br/>
     <input type="radio" name="test" id="test2" />test2<br/>
     <input type="radio" name="test" id="test3" />test3</br>
To get selected value:
$('input:radio[name=test]:checked').val();
 
To perform an action when click the radio button

$(function(){

$('input:radio[name=test]').change(
    function(){
        alert('changed');   
    }
);          

});
To set the first button checked:
$('input:radio[name=test]:nth(0)').attr('checked',true);
or
$('input:radio[name=test]')[0].checked = true;

No comments:

Post a Comment