Reputation: 578
I have a table that automatically adds new rows, once u go to the last cell and tab over.
I click on one of the cells - I want to know the rowIndex of the clicked cell (row)
I havent been able to uniquely identify the cell using any attribute eg classname etc, ID is randomly generated. Name , TagName everything is generic - Same for all rows.
How do I get the rowIndex just using a cell's info
No jquery sols pls - not allowed in my framework
Upvotes: 1
Views: 1619
Reputation: 193261
You can grab this info from the parent node tr
as rowIndex
:
td.parentNode.rowIndex
Here td
is HTMLTableCellElement
element.
td
has a reference to its parent row element parentNode
(tr), which in its own turn has a property rowIndex
. Similarly td
itself has a property cellIndex
.
Upvotes: 3
Reputation: 78
dfsq provides a good answer, but it uses jquery which you said you could not use. You could put this in each rowonclick="myFunction(this)"
then define the function
function myFunction(x)
{
alert("Row index is: " + x.rowIndex);
}
Upvotes: 1