Javascript: getElementsByName td name

Source: Internet
Author: User

Problem:
When writing a dynamic HTML table today, we need to use statistics on the data in td. During the generation, we set the name attribute of td, but document. getElementsByName ("_ test") can obtain this object and print and display the [object] directly, but the length attribute is always 0, no matter how many td names you add, the length obtained by getElementsByName is always 0 !!!

Thanks:
XlingFairy's article: Strange getElementsByName ()

Causes and solutions:
In the original HTML syntax, the td has no name attribute, thanks to the article written by the above-mentioned friend, and he mentioned that if there is no name, getElementsByName will capture the id attribute !! So here I set the td id to "_ test" When dynamically generating the table, and then getElementsByName will get the correct data and print the length. Happy:) Thanks again xlingFairy!

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.