Differences between document. getelementsbyname () and document. getelementbyid () and document. getelementsbytagname ()

Source: Internet
Author: User
Document. getelementsbyname () obtains the control object based on the control name. Because the control name can be the same, an array of objects is returned.
Document. getelementbyid () is used to obtain the control object based on the control ID. Because the Control ID is unique, an object is returned.
Document. getelementsbytagname () is used to obtain the control object based on the control tag, and an array of objects is returned.
For example:
Controls in HTML are as follows:
<Input type = "radio" id = "radio1" Checked = "checked" name = "radiogroup1" value = "1"/>
<Input type = "radio" id = "Radio2" name = "radiogroup1" value = "2"/>
<Input type = "radio" id = "radio3" name = "radiogroup1" value = "3"/>
Then:
Document. getelementsbyname ('radiogroup1') gets the three controls. You can use document. getelementsbyname ('radiogroup1') [0] to get the first one.
Document. getelementbyid ('radio1') gets the first control,

Document. getelementsbytagname ('input') gets the three controls,

You can use document. getelementsbytagname ('input') [0] to obtain the first control.

Getelementsbyname ('delid') returns an array composed of all controls named 'delid'. An array is a collection.

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.