Js obtains the number of rows and columns of a table (compatible with IE and firefox)

Source: Internet
Author: User

This article describes how to obtain the number of rows and columns of a table through js. For example, if the id attribute value of a table is test, you can use javascript to get the number of rows and columns of the table as follows (compatible with ie and firefox !) :

Var tab = document. getElementById ("test"); // table row var rows = tab. rows. length; // Number of table columns var cells = tab. rows. item (0 ). cells. length; alert ("number of rows" + rows + "Number of columns" + cells );
Articles you may be interested in
  • Js can only enter numbers and numbers with decimal points, compatible with IE and firefox
  • Js shields mouse and keyboard events (including right-click, direction key, backspace key, F5 refresh key, etc.), compatible with IE and firefox
  • Js obtains the height of the scroll bar from the top and bottom of the browser. It is compatible with ie and firefox.
  • Javascript to get the current mouse position (compatible with IE and firefox)
  • Jquery drop-down menu (ultra-simple and practical, compatible with mainstream browsers such as IE and firefox)
  • Js to get the current mouse position, compatible with ie and firefox
  • Javascript shield right-click, compatible with IE and firefox
  • JavaScript to get the number of rows and columns of a table

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.