<html>
<head>
<style>
table, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</table>
<p>Click the button to return the position of each cell in the table row.</p>
<p id="demo"></p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var x = document.getElementsByTagName("td");
var txt = "";
var i;
for (i = 0; i < x.length; i++) {
txt = txt + "The index of Cell " + (i + 1) + " is: " + x[i].cellIndex + "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_td_cellindex2 by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 03:17:49 GMT -->
</html>