Hi guys,
I've got a checkbox inside a table, and when you click on it, it'll change the background colour accordingly like so...
$("#table tr td :checkbox").bind("click change", function() {
$this = $(this); // cache the jquery object
if($this.is(':checked')) { $this.closest('tr').css('background-color', 'lightyellow'); }
else { $this.closest('tr').css('background-color', '#fff'); }
});
That works just fine, however, I figured I'd like to go one better, so anywhere on the table row you click, it'll check the box and highlight the row.
I tried using this code, but it doesn't work unfortunately:
$("table tr").bind("click", function() {
$(this).parents("tr").find(":checkbox").attr('checked');
});
And here's the HTML code (removed excessive stuff to improve readability...
<td>Name</td>
<td>Description</td>
<td><input type="checkbox"></td>
Any help would be very much appreciated, thank you!