Js obtains the number of rows and columns of a table. js obtains the number of rows and columns.
How can I use JavaScript to obtain the number of rows and columns of a table? In fact, it is very simple. Assume that 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 code retrieves the number of rows and columns of the table:
// Table row var rows = document. getElementById ("example_table "). rows. length; // Number of table columns var cells = document. getElementById ("example_table "). rows. item (0 ). cells. length;
Using the above code, you can easily obtain the number of rows and columns of a table through JavaScript. I hope this article will be helpful for your learning.