Change style based on checkboxes w/jQuery
- by santa
I need to change the style of the entire row when a checkbox in that row is checked or unchecked.
function myFunc() {
if ($(".chkbx:checked").length) {
$(this).parent().parent().css("background-color","red");
} else {
$(this).parent().parent().css("background-color","green");
}
}
myFunc();
$(".chkbx").change(myFunc);
<table>
<tr>
<td><input type="checkbox" class="chkbx" checked></td>
<td>label 1</td>
</tr>
<tr>
<td><input type="checkbox" class="chkbx" checked></td>
<td>label 1</td>
</tr>
<tr>
<td><input type="checkbox" class="chkbx" checked></td>
<td>label 1</td>
</tr>
</table>
I think I'm missing something here...