Skip to content
Related Articles

Related Articles

HTML | DOM TableHeader cellIndex Property
  • Last Updated : 31 Oct, 2019

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 return the cellIndex Property:
    tableheaderObject.cellIndex

    Return Value: It returns a numeric value which 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 access th element -->
        <script>
            function myGeeks(x) {
                alert("cell index is: " + x.cellIndex);
            }
        </script>
    </body>
      
    </html>

    Output:
    Before Clicking On Table cell:

    After Clicking On Table cell:

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

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



    My Personal Notes arrow_drop_up
  • Recommended Articles
    Page :