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: