Open In App

HTML | DOM TableData cellIndex Property

Last Updated : 01 Nov, 2019
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report
The TableData cellIndex Property is used for returning the position of a cell in the cells collection of a table row. Syntax:
  • It return the cellIndex Property.
    tabledataObject.cellIndex 
Return Value: It returns a numeric value which represents the position of the cell in the cells collection of the table row Example: html
<!DOCTYPE html> 
<html> 
    
<head> 
    <style> 
        table, th, td { 
            border: 1px solid green; 

        } 
    </style> 
</head> 

<body> 

    <h1> 
        GeeksForGeeks 
    </h1> 
        
    <h2>HTML DOM TableData cellIndex Property</h2> 
    <p> 
        Click on the row to get the cell index of the TableData
    </p>
    <table> 
        <tr> 
            <td id = "GFG" onclick="myGeeks(this)">Geeks</td> 
            <td>Geeks</td> 
            <td id = "GFG" onclick="myGeeks(this)">For</td> 
            <td id = "GFG" onclick="myGeeks(this)">Geeks</td>
            <td id = "GFG" onclick="myGeeks(this)">Geeks</td> 
            <td id = "GFG" onclick="myGeeks(this)">Geeks</td> 
            <td id = "GFG" onclick="myGeeks(this)">For</td> 
            <td id = "GFG" onclick="myGeeks(this)">Geeks</td> 
            <td id = "GFG" onclick="myGeeks(this)">Geeks</td> 
            <td id = "GFG" onclick="myGeeks(this)">Geeks</td> 
            <td id = "GFG" onclick="myGeeks(this)">For</td> 
            <td id = "GFG" onclick="myGeeks(this)">Geeks</td> 
        </tr> 
    </table> 

    <p id = "sudo"></p>

    <script> 
    function myGeeks(x) {
        alert("cell index is: " + x.cellIndex);
}
</script>
    </script> 
</body> 

</html>
Output: Before Clicking On Table cell: After Clicking On Table cell: Supported Browsers: The browsers supported by DOM TableData cellIndex Property are listed below:
  • Google Chrome
  • Internet Explorer
  • Firefox
  • Apple Safari
  • Opera

Next Article
Article Tags :

Similar Reads