Open In App

HTML DOM TableHeader cellIndex Property

Last Updated : 19 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

the TableHeader cellIndex Property in HTML DOM is used for returning the position of a cell in the cells collection of a table row.

Syntax: 

  • It returns the cellIndex Property:
tableheaderObject.cellIndex

Return Value: It returns a numeric value that represents the position of the cell in the cells collection of a table row. 

Example: 

HTML




<!DOCTYPE html>
<html>
   
<head>
    <!-- style to set border -->
    <style>
        table,
        th,
        td {
            border: 1px solid black;
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
    <h2>DOM TableHeader CellIndex Property</h2>
    <table>
        <tr>
            <th id="gfg" onclick="myGeeks(this)">
                Username
            </th>
            <th id="gfg" onclick="myGeeks(this)">
                Id
            </th>
        </tr>
        <tr>
            <td>geeks</td>
            <td>23456</td>
        </tr>
    </table>
    <p>
        Click on TableHeader to get the CellIndex th element.
    </p>
 
    <!-- Script to return cellIndex Property -->
    <script>
        function myGeeks(x) {
            alert("cell index is: " + x.cellIndex);
        }
    </script>
</body>
   
</html>


Output: 

 

Supported Browsers: The browsers supported by DOM TableHeader cellIndex Property are listed below:

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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads