Javascript examples for DOM HTML Element:TableData
TableData cellIndex Property - Return the index position of each cell in a table row:
<!DOCTYPE html> <html> <head> <style> table, td { border: 1px solid black; } </style>//from ww w . j a v a 2 s. com </head> <body> <table> <tr> <td>Cell 1</td> <td>Cell 2</td> <td>Cell 3</td> <td>Cell 4</td> </tr> </table> <p id="demo"></p> <button onclick="myFunction()">Test</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> </html>