HTML | DOM TableRow rowIndex Property

The TableRow rowIndex property in HTML DOM is used to return the position and index of row among the collection of rows.

Syntax: It returns the rowIndex property.

tablerowObject.rowIndex

Return Value: It returns the numeric value which represents the position of a row in the rows collection of a table.

Example:




<!DOCTYPE html> 
<html
      
<head
    <title>
        HTML DOM tableRow rowIndex Property
    </title>
      
    <style
        table, th, td { 
            border: 1px solid green; 
        
    </style
</head
  
<body
    <h1
        w3wiki 
    </h1
          
    <h2>HTML DOM tableRow rowIndex Property</h2
      
    <p
        Click on the row to get the
        index of the rows
    </p>
      
    <table
        <tr id = "GFG" onclick="myBeginner(this)"
            <td>Beginner</td
            <td>Beginner</td
            <td>For</td
            <td>Beginner</td
        </tr
        <tr id = "GFG" onclick="myBeginner(this)"
            <td>Beginner</td
            <td>Beginner</td
            <td>For</td
            <td>Beginner</td
        </tr
        <tr id = "GFG" onclick="myBeginner(this)"
            <td>Beginner</td
            <td>Beginner</td
            <td>For</td
            <td>Beginner</td
        </tr
    </table
  
    <p id = "sudo"></p>
  
    <script
        function myBeginner(x) {
            alert("Row index is: " + x.rowIndex);
        }
    </script>
</body
  
</html>


Output:

  • Before Clicking on Row element:
  • After Clicking on Row element:

Supported Browsers: The browsers supported by HTML DOM tableRow rowIndex property are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Safari
  • Opera


Contact Us