Document.all is a read-only deprecated instance property that returns an HTMLAllCollection of every element in document order. Learn how legacy code used it, why typeof document.all === "undefined" is a famous quirk, and how querySelectorAll replaces it—with five examples and try-it labs.
01
Kind
Read-only property
02
Returns
HTMLAllCollection
03
Status
Deprecated
04
Order
Document order
05
Replace
querySelectorAll
06
Quirk
typeof undefined
Fundamentals
Introduction
In very old web pages, developers sometimes grabbed every element with document.all instead of modern selectors. The property returns a collection you can index like an array or look up by legacy id / name strings.
MDN’s modern recommendation is straightforward: use document.querySelectorAll("*") when you truly need every element, or a more specific selector when you do not.
💡
Learn it, don’t ship it
Study document.all to understand legacy tutorials and browser compatibility history—including the odd typeof document.all behavior documented on HTMLAllCollection.
The count includes every element node in the document tree—often much larger than you expect on complex pages.
Example 2 — MDN Replacement with querySelectorAll("*")
Modern equivalent for all elements in document order.
JavaScript
const modern = document.querySelectorAll("*");
console.log(modern.length);
console.log(modern[0].nodeName);
// Same document-order element list — standard API
Document.all is deprecated but still implemented for compatibility in major browsers. MDN recommends querySelectorAll instead. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Deprecated · Legacy
Document.all
Legacy HTMLAllCollection of every element — use querySelectorAll in new code.
LegacyCompatibility only
Google ChromeCompatibility support · prefer modern APIs
Legacy support
Mozilla FirefoxCompatibility support · typeof quirk
Legacy support
Apple SafariCompatibility support
Legacy support
Microsoft EdgeChromium compatibility layer
Legacy support
OperaFollow Chromium behavior
Legacy support
Internet ExplorerOriginal legacy target
Legacy support
Document.allAvoid in new code
Bottom line: Recognize document.all in old scripts. For new DOM queries, use querySelector, querySelectorAll, or getElementById — never document.all.
Wrap Up
Conclusion
Document.all is a deprecated read-only window into every element on the page. It is valuable for understanding legacy DOM code and browser history—not for building new features. Use modern query APIs instead.
Learn the typeof quirk to read old IE-detection snippets
Prefer specific selectors over "*" when possible
❌ Don’t
Query elements with document.all in new projects
Assume it is really undefined because typeof says so
Loop every element on large pages without a good reason
Rely on named document.all[id] lookups
Confuse HTMLAllCollection with a real Array
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.all
Deprecated collection — prefer querySelectorAll.
5
Core concepts
📄01
Returns
HTMLAllCollection
API
⚠️02
Status
deprecated
Legacy
🔍03
Replace
querySelectorAll
Modern
🔢04
Access
index / id
Legacy
🧐05
Quirk
typeof undefined
History
❓ Frequently Asked Questions
A read-only HTMLAllCollection containing every element in the document, in document order. It is rooted at the document node.
Yes. MDN marks Document.all and HTMLAllCollection as deprecated. Use document.querySelectorAll('*') or more specific selectors in new code.
For historical IE-detection compatibility, document.all behaves like undefined in typeof, boolean, and loose equality checks — even though it is still an object in other contexts.
document.all returns an HTMLAllCollection with legacy indexed and named access. querySelectorAll returns a static NodeList and is the modern, recommended API.
Legacy code used document.all[id] or document.all.item(id). Prefer document.getElementById(id) or querySelector('#id') today.
No. It exists mainly for backward compatibility. Use querySelector, querySelectorAll, getElementById, or getElementsByClassName instead.
Did you know?
document.all is one of the few objects in JavaScript whose typeof is "undefined" even though it is still an object. That deliberate quirk preserved decades-old browser-sniffing patterns when modern engines added compatibility support.