HTML | DOM TableData cellIndex Property

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : Akanksha_Rai

Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.