1. Technology

Five Most Common Coding Errors



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.

Readers Respond: Ways I Have Seen JavaScript Misused And How I Would Have Done it Differently

  1. About.com
  2. Technology
  3. JavaScript
  4. Javascript Tutorials
  5. document.all

©2014 About.com. All rights reserved.