Takács Zoltán Takács Zoltán - 3 months ago 9
jQuery Question

Add class to the row where the checkbox is in

How can i add a class to the row, where the checkbox i selected, is in the tr?

Now, it selects all the , exept the one i wanted.

Thanks for help!

echo '<tr id="sor'.intval($a['kapcsolat_id']).'">
<td class="left"><input class="table_row_checkbox" type="checkbox" name="selectedRows[]" value="'.intval($a['kapcsolat_id']).'" /></td>
<td style="text-align: center;">'.intval($a['kapcsolat_id']).'</td>
<td class="left">'.html($a['kapcsolat_nev']).'</td>
<td class="left">'.html($a['kapcsolat_email']).'</td>
<td class="left">'.html($a['kapcsolat_tel']).'</td>
<td style="text-align: center;">'.date_substr($a['kapcsolat_date']).'</td>
<td style="text-align: center; color:'.$color.'">'.$status.'</td>
<td class="right">
<a href="http://'.$_SERVER['HTTP_HOST'].'/'.$admin_folder.'/beerkezett-uzenet.php?id='.intval($a['kapcsolat_id']).'"><span class="btn btn-sm button"><span class="glyphicon glyphicon-pencil"></span></span></a>
<a id="'.intval($a['kapcsolat_id']).'" href="#" class="deleteLink"><span class="btn btn-sm btn-danger "><span class="glyphicon glyphicon-remove"></span></span></a>
</td>
</tr>';



$('.table_row_checkbox').change(function(){
if($(this).is(":checked")) {
$(this).closest(":has(tr)").find('tr').addClass("checkbox_checked_row");
}
else {
$(this).closest(":has(tr)").find('tr').removeClass("checkbox_checked_row");
}
});

ubm ubm
Answer
    $(function(){

    $('.table_row_checkbox').on('change',function(){
    if($(this).is(":checked")) {
        $(this).parents('tr').addClass("checkbox_checked_row");
    } 
    else {
        $(this).parents('tr').removeClass("checkbox_checked_row");
    }
});
});