Home >Web Front-end >JS Tutorial >js method to get the number of rows and columns of a table_javascript skills
How to use JavaScript to get the number of rows and columns of a table? It’s actually very simple, assuming the following table exists:
<table width="100%" border="1" cellspacing="0" cellpadding="0" id="example_table"> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table>
The following codes can be used to obtain the number of rows and columns of the table:
//表格行数 var rows = document.getElementById("example_table").rows.length; //表格列数 var cells = document.getElementById("example_table").rows.item(0).cells.length;
You can use the above code to easily obtain the row number and column of the table through JavaScript. I hope this article will be helpful to your study.