files/en-us/web/api/htmlallcollection/index.md
{{APIRef("DOM")}}{{Deprecated_Header}}
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 {{domxref("document.all")}} property.
HTMLAllCollection has a very similar shape to {{domxref("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.
id or name attribute. Returns null if no element is found.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.
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 {{domxref("HTMLAllCollection/item", "item()")}} method when given the same arguments.
For historical reasons, document.all is an object that in the following ways behaves like undefined:
undefined and null.typeof is "undefined".These special behaviors ensure that code like:
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:
undefined or null.??) or the optional chaining operator (?.), it will not cause the expression to short-circuit.{{Specifications}}
{{Compat}}