Home  >  Article  >  Web Front-end  >  Introduction to the distinction between document.getElementByid, document.all and document.layers in js_javascript skills

Introduction to the distinction between document.getElementByid, document.all and document.layers in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:58:33995browse

document.all is a proprietary attribute of IE 4.0 and above. It is a group representing all objects of the current document, including not only visible entity objects on the page, but also some invisible objects, such as html comments and so on. In the document.all array, the elements are not hierarchical and are listed in parallel according to the order in which they appear in the document. So you can use a numerical index to reference any element. But it is more commonly used to refer to a specific object by object id, such as document.all["element"].
document.layers is a property exclusive to Netscape 4.x. It is an array representing all elements positioned by storage such as

. It is usually referenced by the id attribute of the
or object, but it does not contain other elements.
In fact, these two attributes are not comparable. Maybe you often see them appearing at the same time. There is a historical reason for this. When the fourth generation browsers appeared, the standards were quite confusing. Netscape and Microsoft launched their Navigator 4.x and IE 4.0 respectively. The huge differences between these two browsers also made developers face the problem of making web pages cross-browse. A server compatibility nightmare. Document.layer and document.all are the most prominent signs of the two respectively. In order to determine which browser the viewer is using, it is usually judged by whether document.layers and document.all exist.
The new unified standard uses a series of methods such as document.getElementById to refer to DOM objects, and Netscape gave up the layers feature after 6.0. Although IE continued to retain document.all, this ultimately did not become part of the DOM standard. I hope that document.layers and document.all can pass away soon, so that the standard can be deeply rooted in the hearts of the people!
Code example:

Copy code The code is as follows: