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


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


source


I am wondering why the index of this node is needed?

You can assign



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

0


source


0


source







All Articles