Skip to content
Related Articles

Related Articles

HTML | DOM TableData cellIndex Property
  • Last Updated : 01 Nov, 2019

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:




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

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up
Recommended Articles
Page :