JavaScript

  1. Home
  2. Computing & Technology
  3. JavaScript

Five Most Common Coding Errors

document.all

By Stephen Chapman, About.com

Internet Explorer 4 introduced the document.all DOM (document object model) to allow access to the various parts of the web page. Soon after that the standard DOM method getElementById was introduced and is therefore available in all version 5+ browsers. This means that the document.all references are only needed to support IE4.

Just about no one runs IE4 any more and so support for the document.all DOM is no longer required. It is really surprising though how namy people still use it in their coding. Worse is that support for the document.all DOM is often tested for in order to determine the browser being used and if it is supported then the code assumes that the browser is Internet Explorer (which is completely wrong usage since Opera also recognises that DOM).

Use of document.all anywhere in a script is a clear indication that either the script was originally written for IE4 or the person who wrote the script doesn't know the latest Javascript standards.

Using that DOM reference is never required unless you intend to provide support for IE4 as well as the more recent browsers. If you do intent to use it to support IE4 then you should first test that document.getElementById is not supported and only then test if document.all is supported. Then you will know that the browser is definitely IE4 and not one of the more recent versions of IE or Opera which support that ancient DOM as well as the standard one.

Explore JavaScript

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

JavaScript

  1. Home
  2. Computing & Technology
  3. JavaScript
  4. Javascript Tutorials
  5. document.all

©2009 About.com, a part of The New York Times Company.

All rights reserved.