** EDIT** I'm very sorry. I need the td index, not the row index.
Using jQuery, how do I get the index of the td lblName
is in?
<table>
<tr>
<td>
</td>
<td>
<label id="lblName" />
</td>
<td>
</td>
</tr>
</table>
Update for updated question:
$('#lblName').parent().index();
or
document.getElementById('lblName').parentNode.cellIndex
Original answer:
Use .index()
.
$('#lblName').closest('tr').index();
The .index()
method has a few different use patterns.
This one means "take the first element matched by the selector, and return its zero based index of its position among its siblings".
Or natively, do this...
document.getElementById('lblName').parentNode.parentNode.rowIndex
Or combine the two...
$('#lblName').closest('tr')[0].rowIndex;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With