JavaScript Document all Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

document.all is a read-only property that returns an HTMLAllCollection of every element in the document, in document order (MDN).

Read the notes below before you get or set this property. Prefer feature detection when support is limited.

Syntax

Use document.all. Start with this line.

JavaScript
document.all
CallWhat it does
document.allPrimary signature.

Built into the browser. Read or assign document.all — no import required.

Library declarations
JavaScript
document.all

Parameters

ParameterDescription
Writable?Optional. Read-only

Return Value

Return ValueDescription
*HTMLAllCollection

JavaScript Examples

Example 1 — Count Elements with all.length

Read the size of the legacy collection.

JavaScript
console.log(document.all.length);
console.log(document.all[0].tagName);
Try It Yourself

How It Works

  1. Access document.all. Returns an HTMLAllCollection (MDN).
  2. Read .length. Number of elements in the document.
  3. Index with [0]. First element in document order (often HTML).
  4. Deprecated. Prefer querySelectorAll("*").length for new code.

Example 2 — The typeof Quirk

MDN: document.all pretends to be undefined in some checks.

JavaScript
console.log(typeof document.all);       // "undefined"
console.log(!!document.all);            // false
console.log(document.all == null);      // true
console.log(document.all === undefined); // false
console.log(document.all.length > 0);   // true
Try It Yourself

How It Works

  1. typeof. Returns "undefined" for old if (document.all) IE detection (MDN).
  2. Boolean context. Falsy, so the IE branch does not run in modern browsers.
  3. Loose vs strict. == null is true; === undefined is false.
  4. Still a collection. .length and indexing work as an object.

Example 3 — Prefer querySelectorAll("*")

MDN’s recommended replacement for listing every element.

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

console.log(allElements.length);
console.log(allElements[0].tagName);
console.log(allElements.constructor.name); // "NodeList"
Try It Yourself

How It Works

  1. Select all elements. "*" matches every element (MDN).
  2. Get a NodeList. Modern, iterable, no typeof quirks.
  3. Same ordering idea. Document order, like document.all.
  4. Prefer specific selectors when you do not need the entire tree.

Browser Support

Document.all returns a deprecated HTMLAllCollection. MDN marks it Deprecated. Still present for compatibility, with special typeof behavior.

✓ Deprecated

Document.all

Available in major browsers for legacy pages. New code should use querySelectorAll("*") or getElementById.

Legacy Deprecated API
Google Chrome Legacy support
Yes
Microsoft Edge Legacy support
Yes
Mozilla Firefox Legacy support
Yes
Apple Safari Legacy support
Yes
Opera Legacy support
Yes
Internet Explorer Original home of .all
Yes
document.all Prefer querySelectorAll

Bottom line: Learn it to read old scripts. See the MDN Document.all reference and migrate to querySelectorAll.

Frequently Asked Questions

A read-only HTMLAllCollection containing every element in the document, in document order. It is rooted at the document node (MDN).
Yes. MDN marks Document.all and HTMLAllCollection as Deprecated. Prefer 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 (MDN).
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 getElementsByTagName instead.

Next: Document anchors

Learn the legacy document.anchors collection of named anchors.

anchors tutorial →

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.

11 people found this page helpful