Looping through my table, how do I know if the checkbox is checked?

Posted by radbyx on Stack Overflow See other posts from Stack Overflow or by radbyx
Published on 2013-11-05T09:50:05Z Indexed on 2013/11/05 9:53 UTC
Read the original article Hit count: 211

Filed under:
|
|
|

How I build my table:

for (var i = 0; i < result.length; i++) {
    var item = result[i];

    // Firma, BygningselementNavn, BrugerNavn, EmailAdresse, Telefon
    tbody = tbody + '<tr class="modtagerRow"><td>' + item.FirmaNavn + '</td>' +
                                '<td>' + item.BygningselementNavn + '</td>' +
                                '<td>' + item.BrugerNavn + '</td>' +
                                '<td>' + item.EmailAdresse + '</td>' +
                                '<td>' + item.Telefon + '</td>'
    // Medtag
    tbody = tbody + '<td style="text-align:center"><input type="checkbox" 
            value="' + item.BygningselementId + '_' + item.BrugerId + '" 
            name="BygningsElementBrugerComboIds"></td>' + '</tr>';
}
$('#ModtagereTable tbody').append(tbody)

How I am trying to loop through the rows and adding a CSS class to rows that has it's checkbox checked.

1) I get the indexies to the console, but I can't make the if condition for all the checked checkboxes.

2) Also I am not sure if I can you $( this ) or I should use something else, when adding the class .hideForSendMailConfirm?

// Looping rows in table
$( ".modtagerRow" ).each(function(index, element) {
    console.log('index: ' + index);
    // if
    if (element.checked) {
        $( this ).addClass(".hideForSendMailConfirm");
    }
});

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery