Get the form object, getelementbyid (), getelementsbyname (), and getelementsbytagname () and usage

Source: Internet
Author: User

Document. form name. object Name. attribute values may not be supported by third parties in this way. We recommend that you use the getelementbyid (), getelementsbyname (), and getelementsbytagname () methods () the result is an array.
On the Internet, I searched for relevant information and provided it for your reference:
Most third-party browsers are "strict standards" implementations, meaning that they implement W3C and ECMA standards and ignore most of the proprietary
Object Models of Internet Explorer and Netscape. If the demographic for your web site des users likely to use less common browsers, such as Linux
Aficionados, it might be a good idea to avoid ie-specific features and use the W3C Dom instead. by Internet Explorer 6, we see that IE implements
Significant portions of the W3C Dom.
This section means that most third-party browsers only support W3C Dom. If your website users use other browsers, you 'd better avoid using the private properties of IE. IE6 also began to support W3C Dom.
After all, most people do not understand the standard. before using the standard, you can also use document on your webpage. all [] access document objects are previously written to the Web standard. To continue the Web standard today, you can use getelementbyid (),
Getelementsbyname (), and getelementsbytagname () access any tag in the document:

1. getelementbyid ()
Getelementbyid () can access a specific element in the document. As the name suggests, the element is obtained by ID. Therefore, only the element with the ID set can be accessed.
For example, the ID of a div is docid:
Program code
<Div id = "docid"> </div>
You can use getelementbyid ("docid") to obtain this element.
2. getelementsbyname ()
This is an element obtained by name, but I do not know whether it is. This is get elements. The Plural elements indicates that it is not an element. Why?
The ID of each element in the document is unique, but the name can be repeated. A metaphor is like a person's ID card number is unique (theoretically, although there are duplicates in reality), but there are many duplicate names. If a document
If more than two tags have the same name, then getelementsbyname () can get these elements to form an array.
For example, there are two divs:
Program code
<Div name = "docname" id = "docid1"> </div>
<Div name = "docname" id = "docid2"> </div>
You can use getelementsbyname ("docname") to obtain the two divs, use getelementsbyname ("docname") [0] to access the first Divs, and use getelementsbyname ("docname ") [1] access the second Div.
3. getelementsbytagname ()
In this case, the tagname is used to obtain the element. Of course, a document contains the same tag, so this method also gets an array.
In the following example, there are two divs. You can use getelementsbytagname ("Div") to access them and use getelementsbytagname ("Div") [0] to access the first Div.
Getelementsbytagname ("Div") [1] access the second Div.

To sum up the standard DOM, try to use the standard getelementbyid () for accessing a specific element, and use the standard getelementbytagname () for the access tag. However, ie does not support getelementsbyname (), so avoid using
Getelementsbyname (), but getelementsbyname () does not conform to the standard document. all [] is not completely useless. They have their own convenience. If you don't need to use them, you can see what browsers the website users use.
Decided

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.