Got a small problem with some very basic jQuery, I'd like to be able to click on a table cell, and then have it automatically select the radio button inside.
HTML:
<table>
<tr>
<td>
1<br>
<input type="radio" name="choice" value="1">
</td>
<td>
2<br>
<input type="radio" name="choice" value="2">
</td>
<td>
3<br>
<input type="radio" name="choice" value="3">
</td>
</tr>
</table>
jQuery:
$("td").click(function () {
$(this).closest('input:radio').attr('checked',true);
});
Any help would really be appreciated, thank you!
.closest()
is for traversing up the DOM tree, e.g. getting the<tr>
or the<table>
, rather than down. – Industrials