If I have a body like the following... I know that if I click the first radio it returns 1. If I click the one on the outside of the table it returns 2. But when I click the nested table's first td it returns its index plus the 'parent's td index in two alerts. How can I return the nested td index only which should be 2? This is just a sample table structure that is dynamically built so it needs to work with virtually any table design and any td.
Any suggestions?
This is the code I am using to return the index when a user clicks on a td (I capture other indexes for an input, textarea, etc):
$("td").click(function (event) {
var nodeIndex = $("td").index();
var nodeName = $(this).get(0).nodeName
alert(nodeName + "," + nodeIndex);
});
This is the sample body:
<body>
<input type="radio" />
<table class="parent_table">
<tr>
<td>
<table class="nested_table">
<tr>
<td>
Sample Text</td>
<td>
</td>
</tr>
</table>
</td>
<td>
</td>
</tr>
</table>
<input type="radio" />
</body>