Differences between document. getElementByid, document. all, and document. layers in js _ javascript skills

Source: Internet
Author: User
Document. getElementById is a public standard and supported by all mainstream browsers, document. all only supports IE, document. layers is the proprietary document of Netscape4.x. all is a proprietary attribute of IE 4.0 and later versions. It is a group of all objects in the current document, including not only object objects visible on the page, but also invisible objects, for example, html annotations. In the document. all array, elements are listed in parallel according to the order in which they appear in the document. Therefore, you can use a digital index to reference any element. However, it is commonly used to reference a specific object with the Object id, such as document. all ["element.
Document. layers is a proprietary attribute of Netscape 4.x. It represents all

Array of elements. It is usually used

Or The id attribute of the object to reference, but it does not contain other elements.
In fact, these two attributes are not comparable. You may often see a historical reason when they come out at the same time. When the fourth generation of browsers appeared, the standards were quite messy. Netscape and Microsoft released their Navigator 4. x and IE 4.0, the huge difference between the two browsers, also makes developers face a nightmare of cross-browser web page compatibility. Document. layer and document. all are two of the most significant signs. To determine which browsers the viewer uses, we usually judge whether document. layers and document. all exist.
The new Unified Standard Uses document. getElementById and other methods to reference DOM objects, and Netscape 6.0 later abandoned the layers feature, although IE continues to retain the document. all, but this does not end up being part of the DOM standard. We hope that document. layers and document. all can be used as early as possible, so that the standards will become deeply rooted in the hearts of the people!
Sample Code:

The Code is as follows:


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.