JavaScript to get the number of rows and columns of a table

Source: Internet
Author: User

How can I use JavaScript to obtain the number of rows and columns in 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>&nbsp;</td>        <td>&nbsp;</td>        <td>&nbsp;</td>        <td>&nbsp;</td>        <td>&nbsp;</td>    </tr>    <tr>        <td>&nbsp;</td>        <td>&nbsp;</td>        <td>&nbsp;</td>        <td>&nbsp;</td>        <td>&nbsp;</td>    </tr>    <tr>        <td>&nbsp;</td>        <td>&nbsp;</td>        <td>&nbsp;</td>        <td>&nbsp;</td>        <td>&nbsp;</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;
Articles you may be interested in
  • Js obtains the number of rows and columns of a table (compatible with IE and firefox)
  • Jquery achieves the effect of table row-changing
  • Js can only enter numbers and numbers with decimal points, compatible with IE and firefox
  • Javascript restricts that only numbers (including decimal places) can be entered in the text box)
  • Js restrictions: Only English letters and numbers can be entered. Chinese characters and other special characters cannot be entered.
  • When CuteFTP is connected to the ftp server, the "invalid Parameters" error is displayed.
  • How to obtain the complete url address and parameters in javascript
  • Smarty loops the table and supplements the table with insufficient td Information

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.