Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery:Looping all radio buttons inside an HTML table

I have an HTML table having n rows and each rows contain one radiobutton in the Row.Using jQuery , How can i look thru these radio buttons to check which one is checked ?

like image 379
Shyju Avatar asked May 17 '10 19:05

Shyju


3 Answers

$('#table tbody tr input[type=radio]').each(function(){
 alert($(this).attr('checked'));
});

HTH.

like image 149
Sunny Avatar answered Sep 19 '22 04:09

Sunny


To loop through all the radio checked radio buttons, you can also do this:

$('input:radio:checked').each(function() {
    //this loops through all checked radio buttons
    //you can use the radio button using $(this)
});
like image 30
SaiyanGirl Avatar answered Sep 19 '22 04:09

SaiyanGirl


There are many ways to do that, e.g., using .each and the .is traversal method:

$("table tbody tr td input[name=something]:radio").each(function() {
    if($(this).is(":checked")) {
        $(this).closest("tr").css("border", "1px solid red");
    } else {
        // do something else
    }
});
like image 44
karim79 Avatar answered Sep 23 '22 04:09

karim79