html5 - How to get the column index of particular value of td in HTML tables -
hi there,
i created html table , need find column index of particular value, don't know how access each value of table. why unable index of column.
here table.
<table> <tr> <td>01</td> <td>02</td> <td>03</td> </tr> <tr> <td>04</td> <td>05</td> <td>06</td> </tr> <tr> <td>07</td> <td>08</td> <td>09</td> </tr> </table>
and want index of value 03.
the following working code, first traverse table values in this, compare required value , find index of it..,
<html> <head> <script> function cellvalues() { var table = document.getelementbyid('mytable'); (var r = 0, n = table.rows.length; r < n; r++) { (var c = 0, m = table.rows[r].cells.length; c < m; c++) { var hi=table.rows[r].cells[c].innerhtml; if(hi==03) { alert(table.rows[r].cells[c].cellindex); } } } } </script> </head> <body> <table id="mytable"> <tr><td>01</td><td>02</td><td>03</td> </tr> <tr><td>04</td><td>05</td><td>06</td> </tr> <tr><td>07</td><td>08</td><td>09</td> </tr> </table> <input type="button" onclick=cellvalues()> </body> </html>
Comments
Post a Comment