GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • MDN
  • HTML: Markup language
  • Elements
  • Global attributes
  • Attributes
  • See all…
  • Responsive images
  • HTML cheatsheet
  • Date & time formats
  • See all…
  • SVG
  • MathML
  • XML
  • CSS: Styling language

This view

  • Original page
  • New address

GeezerVison is showing developer.mozilla.org — HTMLAllCollection - Web APIs | MDN

HTMLAllCollection

Deprecated

Avoid using this feature in new projects. This feature may be a candidate for removal from web standards or browsers.

  • See full compatibility
  • Learn more

The HTMLAllCollection interface represents a collection of all of the document's elements, accessible by index (like an array) and by the element's id. It is returned by the document.all property.

HTMLAllCollection has a very similar shape to HTMLCollection, but there are many subtle behavior differences — for example, HTMLAllCollection can be called as a function, and its item() method can be called with a string representing an element's id or name attribute.

Instance properties

HTMLAllCollection.length Read only

Returns the number of items in the collection.

Instance methods

HTMLAllCollection.item()

Returns the element located at the specified offset into the collection, or the element with the specified value for its id or name attribute. Returns null if no element is found.

HTMLAllCollection.namedItem()

Returns the first element in the collection whose id or name attribute match the given string name, or null if no element matches.

Usage in JavaScript

Indexed access

In addition to the methods above, elements in an HTMLAllCollection can be accessed by integer indices and string property names. The HTML id attribute may contain : and . as valid characters, which would necessitate using bracket notation for property access. collection[i] is equivalent to collection.item(i), where i can be an integer, a string containing an integer, or a string representing an id.

Calling as a function

An HTMLAllCollection object is callable. When it's called with no arguments or with undefined, it returns null. Otherwise, it returns the same value as the item() method when given the same arguments.

Special type conversion behavior

For historical reasons, document.all is an object that in the following ways behaves like undefined:

  • It is loosely equal to undefined and null.
  • It is falsy in boolean contexts.
  • Its typeof is "undefined".

These special behaviors ensure that code like:

js
if (document.all) {
  // Assume that we are in IE; provide special logic
}
// Assume that we are in a modern browser

Will continue to provide modern behavior even if the code is run in a browser that implements document.all for compatibility reasons.

However, in all other contexts, document.all remains an object. For example:

  • It is not strictly equal to either undefined or null.
  • When used on the left-hand side of the nullish coalescing operator (??) or the optional chaining operator (?.), it will not cause the expression to short-circuit.

Specifications

Specification
HTML
# the-htmlallcollection-interface

Browser compatibility

See also

  • HTMLCollection

Help improve MDN

Learn how to contribute

This page was last modified on Sep 10, 2026 by MDN contributors.

View this page on GitHub • Report a problem with this content
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.