O'Reilly logo

Learning JavaScript by Shelley Powers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The all Collection, Inner/Outer HTML and Text, and Old and New Documents

The all collection on the document object contains references to all elements in the document page. It was a concept created by Microsoft as a way to collect all page elements into one array, before the W3C started work on standardizing the object hierarchy.

The document.all collection was one of the earlier methods that accessed individual elements; however, the actual collection itself is no longer supported in many modern browsers, such as Mozilla/Firefox. Still, the concept of being able to access any element in the document still remains; it’s just the approach that has changed. Now, you can use document.getElementById, passing in the element’s identifier to access the individual object.

Tip

In Chapter 10, you’ll see how other methods get all elements of a certain tag or, given a specific name, via the document object.

You’ll see examples of document.all in many older scripts, when it was used to differentiate object support in cross-browser DHTML applications. It’s not uncommon to see code like the following:

if (document.all)  
   elem = document.all['elemid'];
else 
   elem = document.getElementById['elemid'];

This actually works in most browsers. However, Internet Explorer is about the only browser that supports document.all now, so recognize it for what it was, but don’t use it for modern applications. IE 6.x (5.x really) supports getElementById, just like other browsers.

Another interesting item you’ll see in both ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required