Reputation: 1614
I am going through some (old?) native javascript and I encountered a separation of document.getElementById, document.all and document.layers.
From what I know, document.all and document.layers are obsolete now, but I just wanted to make sure.
Upvotes: 11
Views: 14178
Reputation: 41
document.all is supported by most (if not all) modern browsers. It is just considered false if you try to test for it, but will work if you use it (IIRC, they wanted to discourage people from using it to test for IE).
To really test for it you can use try .... catch. What I tested was:
var da = document.all.length;
which throws an error if document.all isn't supported.
The modern equivalent of document.all is document.getElementsByTagName('*')
Upvotes: 0
Reputation: 700690
Yes, they are obsolete.
The document.all
collection is specific to Internet Explorer. The document.layers
collection was specific to Netscape. Neither is in the standards.
Today we use document.getElementById
instead.
Upvotes: 14
Reputation: 25332
Yes, they are. They comes from a period where Internet Explorer 4 and Netscape 4.x were the main browsers: document.layers
was used by Netscape, and document.all
from IE. The first is definitely unused anymore, where I guess document.all
is still used for legacy in IEs.
Upvotes: 2