I have a quick jQuery question:
I have the following type of table:
<table id="my_table">
<tr>
<td><input type="checkbox" value="24"></td>
<td> Click Here To Check The Box </td>
<td> Or Click Here </td>
</tr>
</table>
And in jQuery, I am attempting to select the corresponding checkbox in that row that was clicked.
$("#my_table tr").click(function(e) {
$(this).closest(":checkbox").attr("checked", checked");
});
But the above isn’t working. Any quick ideas on selecting the checkbox on the row that was clicked? Thanks!
EDIT: BEST SOLUTION AT BOTTOM
Assuming there’s only one checkbox, I would attach the event to the
tdinstead of thetr:Example
If you want to be able to uncheck the checkbox as well…
This function needs to be applied to the checkbox as well to negate the default behavior.
Example 2
EDIT: The solution is most reasonable method is to cancel the functionality if the target is an input: http://jsfiddle.net/EXVYU/5/