TableRow sectionRowIndex Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:TableRow


The sectionRowIndex property returns the position of a row in the rows collection of a <tbody>, <thead>, or <tfoot>.

Return Value

A Number, representing the position of the row in the rows collection of a tbody, thead, or tfoot

The following code shows how to Click on different rows to alert their position:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
table, td {
    border: 1px solid black;
</style>//from  w ww . ja v  a2 s .com

    <th>Row 1</th>
    <th>Row 2</th>
    <td>Row 3</td>
    <td>Row 4</td>
    <td>Row 5</td>
    <td>Row 6</td>

<p id="demo"></p>

<button onclick="myFunction()">Test</button>

function myFunction() {
    var x = document.getElementsByTagName("tr");
    var txt = "";
    var i;
    for (i = 0; i < x.length; i++) {
        txt = txt + "The index of Row "+(i+1)+" is: "+x[i].sectionRowIndex+"<br>";
    document.getElementById("demo").innerHTML = txt;


Related Tutorials