Open In App

HTML DOM TableHeader cellIndex Property

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: 



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: 






<!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:


Article Tags :