JavaScript Document all Property

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Deprecated
Instance property

What You’ll Learn

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

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.

Related Document tutorials: alinkColor, activeElement, Document constructor.

Understanding Document.all

A read-only instance property on Document. Its value is an HTMLAllCollection rooted at the document node and containing every element in the page.

  • ValueHTMLAllCollection (deprecated collection type).
  • Read-only — you do not assign a new collection to document.all.
  • Indexed accessdocument.all[i] like an array (legacy).
  • Named accessdocument.all["myId"] or item("myId") (legacy).
  • Special quirk — acts like undefined in typeof, boolean, and loose equality checks for IE-detection compatibility.

📝 Syntax

JavaScript
document.all

Value

An HTMLAllCollection containing every element in the document.

MDN modern replacement

JavaScript
const allElements = document.querySelectorAll("*");

⚡ Quick Reference

GoalCode / note
Legacy: all elementsdocument.all
Count (legacy)document.all.length
Index (legacy)document.all[0]
By id (legacy)document.all.item("id")
Modern: all elementsdocument.querySelectorAll("*")
MDN statusDeprecated

🔍 At a Glance

Four facts about document.all.

Type
HTMLAllCollection

Read-only

Contains
all elements

Document order

Status
deprecated

Legacy API

Use instead
querySelectorAll

Modern DOM

📋 document.all vs querySelectorAll("*")

document.allquerySelectorAll("*")
Recommended?NoYes
Collection typeHTMLAllCollectionNodeList
typeof quirk"undefined" (legacy)Normal object
Best forReading old codeNew element queries

Examples Gallery

Examples follow MDN Document: all and HTMLAllCollection. Use View Output or Try It Yourself for each case.

📚 Getting Started

Inspect the legacy collection and compare with modern APIs.

Example 1 — Read document.all.length

Count every element currently in the document.

JavaScript
console.log(document.all.length);
console.log(document.all.constructor.name);
// "HTMLAllCollection" (where supported)
Try It Yourself

How It Works

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
Try It Yourself

How It Works

Prefer specific selectors when possible—"*" matches every element and can be expensive on large pages.

📈 Legacy Access & Quirks

How old code indexed elements and the famous typeof behavior.

Example 3 — Indexed Access document.all[i]

Legacy collections support numeric indices like arrays.

JavaScript
const first = document.all[0];
console.log(first.nodeName);
console.log(document.all.item(0) === first);
Try It Yourself

How It Works

collection[i] is equivalent to collection.item(i) on HTMLAllCollection.

Example 4 — Lookup by id (Legacy)

Old pattern: document.all.item("demo") instead of getElementById.

JavaScript
// Legacy (deprecated):
const legacy = document.all.item("demo");

// Modern replacement:
const modern = document.getElementById("demo");

console.log(legacy === modern);
Try It Yourself

How It Works

Named lookup on HTMLAllCollection was a pre-getElementById shortcut. Do not use it in new projects.

Example 5 — The typeof Quirk (MDN)

Legacy compatibility: document.all masquerades as undefined in some checks.

JavaScript
console.log(typeof document.all);        // "undefined" (legacy quirk)
console.log(document.all == null);       // true (loose)
console.log(document.all === undefined); // false (strict)
console.log(Boolean(document.all));      // false (falsy in boolean context)
Try It Yourself

How It Works

MDN: this kept old if (document.all) { /* IE */ } checks from breaking when modern browsers added compatibility support.

🚀 Common Use Cases

  • Reading legacy intranet code — recognize document.all loops.
  • Migrating old scripts — replace with querySelectorAll or targeted queries.
  • Teaching DOM history — contrast collections vs modern selectors.
  • Interview trivia — explain the typeof undefined quirk accurately.
  • Not for new apps — never query the whole document via document.all.
  • Debugging — compare all.length vs querySelectorAll("*").length when studying a legacy page.

🧠 How document.all Fits the DOM

1

Page loads elements

The browser builds a tree of element nodes.

DOM
2

Legacy script reads document.all

Returns an HTMLAllCollection in document order.

Legacy
3

Indexed / named access

Old code walks indices or looks up ids via the collection.

Access
4

Prefer modern selectors

Use querySelectorAll, getElementById, and specific CSS selectors instead.

📝 Notes

  • document.all is deprecated (MDN) — avoid in new code.
  • Read-only property; returns HTMLAllCollection, not a plain array.
  • MDN replacement: document.querySelectorAll("*") for all elements.
  • Special typeof / falsy behavior is documented on HTMLAllCollection for IE-detection legacy.
  • Strict equality: document.all === undefined is false even when typeof is "undefined".
  • Related: activeElement, ownerDocument, JavaScript hub.

Legacy Browser Support

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.

Legacy Compatibility only
Google Chrome Compatibility support · prefer modern APIs
Legacy support
Mozilla Firefox Compatibility support · typeof quirk
Legacy support
Apple Safari Compatibility support
Legacy support
Microsoft Edge Chromium compatibility layer
Legacy support
Opera Follow Chromium behavior
Legacy support
Internet Explorer Original legacy target
Legacy support
Document.all Avoid in new code

Bottom line: Recognize document.all in old scripts. For new DOM queries, use querySelector, querySelectorAll, or getElementById — never document.all.

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.

Continue with anchors, ownerDocument, alinkColor, Document constructor, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use querySelector / querySelectorAll for new code
  • Use getElementById for single id lookups
  • Replace document.all when you touch legacy files
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about document.all

Deprecated collection — prefer querySelectorAll.

5
Core concepts
⚠️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.

Next: anchors

Learn the deprecated HTMLCollection behind document.anchors.

anchors →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful