tags:

views:

291

answers:

3

Hi friends,

I need to find out the position of the TR.

actually i got the index of the TD which is 291, But i need to get the index of the TR contains the TD.

We can get the innerHTML by document.getElementsByTagName("td")[291].parentNode.innerHTML..

How to get the index of that parentNode i mean the TR..

Please help me

A: 

I am wondering why you need the index of that node ?

You can assign

var trNode = document.getElementsByTagName("td")[291].parentNode;

krosenvold
+2  A: 
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;
  }
}
Tor Haugen