7

Can anybody tell me the difference between these two JavaScript commands?
Also what is the compatibility of these two across major browsers? I know documentElement is compatible with most browsers.

Thanks

farjad
  • 101
  • 1
  • 9
  • 1
    [Don't use document.all](http://simonwillison.net/2003/Aug/11/documentAll/) – Clive Oct 07 '11 at 22:45
  • 1
    people are speaking about `document.querySelector()` now days... – Mohsen Oct 07 '11 at 22:50
  • The question that makes more sense is about the difference between document.getElementById and document.all http://stackoverflow.com/questions/2408424/document-all-vs-document-getelementbyid since document.documentElement and document.all are completely different beasts – Ruan Mendes Oct 07 '11 at 22:51
  • actually i want to know the working of these two. i think question was asked by me like that it is looking that i want the comparison of these two. sorry about that – farjad Oct 07 '11 at 22:59

2 Answers2

7

document.documentElement is a reference to the root element of the document, usually the <html> tag.

document.all is a collection type, containing an enumeration of all the children tags within the document. It's IE specific and should be avoided for cross-browser scripts.

document.documentElement is DOM Level 2, so should work in pretty much any major browser these days.

Mike Christensen
  • 88,082
  • 50
  • 208
  • 326
  • i was working on a web application that i have to make safari compatible. major issue i faced was document.all was used for IE.is there any equivalent to document.all???? – farjad Oct 07 '11 at 22:55
6

document.all is a proprietary Microsoft extension to the W3C-standard.
It's an old function and should not be used anymore!

rfc document.all vs. document.getElementById

Community
  • 1
  • 1
Tim
  • 662
  • 1
  • 7
  • 16