You are here: Reference > JavaScript > client-side > HTML DOM > properties > cellIndex (td, th)

cellIndex property (td, th)

Browser support:
Returns a zero-based integer that indicates the position of a cell (td or th) in the cells collection of a table row.

Syntax:

object.cellIndex;
You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Zero-based integer that retrieves the position of the td element.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the cellIndex property:
<head>
    <script type="text/javascript">
        function GetCellPos () {
            var cellPos = document.getElementById ("myCell").cellIndex;
            alert (cellPos);
        }
    </script>
</head>
<body>
    <table border="1px">
        <tr>
            <td>First cell in the table</td>
            <td id="myCell">Second cell id = myCell</td>
        </tr>
    </table>
    <button onclick="GetCellPos ()">Get myCell's position!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content