Home JavaScript Document Properties all JavaScript Document all 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.
Call What it does document.allPrimary signature.
Built into the browser. Read or assign document.all — no import required.
Library declarations Parameters Parameter Description Writable? Optional. Read-only
Return Value Return Value Description * HTMLAllCollection
JavaScript Examples 1. Length 2. typeof quirk 3. Modern replacement Example 1 — Count Elements with all.length Read the size of the legacy collection.
console.log(document.all.length);
console.log(document.all[0].tagName); 42
HTML
/* length varies by page */ How It Works Access document.all. Returns an HTMLAllCollection (MDN).Read .length. Number of elements in the document.Index with [0]. First element in document order (often HTML).Deprecated. Prefer querySelectorAll("*").length for new code.Example 2 — The typeof Quirk MDN: document.all pretends to be undefined in some checks.
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 undefined
false
true
false
true How It Works typeof. Returns "undefined" for old if (document.all) IE detection (MDN).Boolean context. Falsy, so the IE branch does not run in modern browsers.Loose vs strict. == null is true; === undefined is false.Still a collection. .length and indexing work as an object.Example 3 — Prefer querySelectorAll("*") MDN’s recommended replacement for listing every element.
const allElements = document.querySelectorAll("*");
console.log(allElements.length);
console.log(allElements[0].tagName);
console.log(allElements.constructor.name); // "NodeList" 42
HTML
NodeList
/* length varies by page */ How It Works Select all elements. "*" matches every element (MDN).Get a NodeList. Modern, iterable, no typeof quirks.Same ordering idea. Document order, like document.all.Prefer specific selectors when you do not need the entire tree.Compatibility
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.
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 Frequently Asked Questions What does document.all return? A read-only HTMLAllCollection containing every element in the document, in document order. It is rooted at the document node (MDN).
Is document.all deprecated? Yes. MDN marks Document.all and HTMLAllCollection as Deprecated. Prefer document.querySelectorAll("*") or more specific selectors in new code.
Why does typeof document.all equal "undefined"? 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).
How is it different from querySelectorAll("*")? document.all returns an HTMLAllCollection with legacy indexed and named access. querySelectorAll returns a static NodeList and is the modern, recommended API.
Can I get an element by id with document.all? Legacy code used document.all[id] or document.all.item(id). Prefer document.getElementById(id) or querySelector("#id") today.
Should I use document.all in new projects? 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 Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion