To get the TR index
I need to know the position of TR.
I actually got the TD index which is 291, But I need the TR index to contain TD.
We can get innerHTML by document.getElementsByTagName ("td") [291] .parentNode.innerHTML ..
How to get the index of this parentNode, I mean TR ..
Please help me
+1
praveenjayapal
source
to share
3 answers
var parent = document.getElementsByTagName("td")[291].parentNode;
var index = -1;
for (var i = 0; i < parent.childNodes.length; i++) {
if (parent.childNodes.item(i) == tr) {
index = i;
break;
}
}
+2
Tor Haugen
source
to share
I am wondering why the index of this node is needed?
You can assign
var trNode = document.getElementsByTagName ("td") [291] .parentNode;
0
krosenvold
source
to share
Here's another example ...
http://www.maratz.com/blog/archives/2005/05/18/detect-table-row-index-with-javascript/
0
rich
source
to share