I am struggling with controlling the highlight of a table using only radio buttons. When I try to change the selector to input:radio, it doesn't work as expected. It seems to only work with the selector provided in my code snippet.
$("th").on("click", function () {
var $currentTable = $(this).closest("table");
var index = $(this).index();
$currentTable.find("td").removeClass("selected");
$currentTable.find("tr").each(function () {
$(this).find("td").eq(index).addClass("selected");
});
});
table tr td {
width: 5em;
}
.selected {
background-color: limegreen;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="options" border="1" cellpadding="0" cellspace="0">
<tr>
<th><input type="radio" name="test" value="1" /></th>
<th><input type="radio" name="test" value="2" /></th>
</tr>
<tr>
<td>col_1</td>
<td>col_2</td>
</tr>
<tr>
<td>col_1</td>
<td>col_2</td>
</tr>
<tr>
<td>col_1</td>
<td>col_2</td>
</tr>
<tr>
<td>col_1</td>
<td>col_2</td>
</tr>
</table>