I have the below table and I am using the below code to get the index of the tr with the id tbl1.The issue is that the index being returned which should be 2 is coming out correct in IE but it is coming as 3 in chrome and firefox.Can someone please tell me what I am doing wrong here.
var parent = document.getElementById("tbl1").parentElement;
var tr = document.getElementById("tbl1");
var index = -1;
for (var i = 0; i < parent.childNodes.length; i++) {
if (parent.childNodes.item(i) == tr) {
index = ++i;
break;
}
}
<TABLE border=0 cellSpacing=0 cellPadding=0><TBODY>
<TR>
</TR>
<TR id="tbl1">
</TR>
<TR></TR>
</TBODY></TABLE>
How about just use
rowIndex:See demo