1. 2.5 Common DOM interfaces
      1. 2.5.1 Reflecting content attributes in IDL attributes
      2. 2.5.2 Collections
        1. 2.5.2.1 The HTMLAllCollection interface
        2. 2.5.2.2 The HTMLFormControlsCollection interface
        3. 2.5.2.3 The HTMLOptionsCollection interface
      3. 2.5.3 The DOMStringList interface

2.5 Common DOM interfaces

2.5.1 Reflecting content attributes in IDL attributes

The building blocks for reflecting are as follows:

A reflected IDL attribute can be defined to reflect a reflected content attribute name of a reflected target. In general this means that the IDL attribute getter returns the current value of the content attribute, and the setter changes the value of the content attribute to the given value.

If the reflected target is an element, then the reflected IDL attribute can additionally declare to support ElementInternals. This means that the ElementInternals interface also has a reflected IDL attribute, with the same identifier, and that reflected IDL attribute reflects the same reflected content attribute name.

The fooBar IDL attribute must reflect the foobar content attribute and support ElementInternals.

2.5.2 Collections

The HTMLFormControlsCollection and HTMLOptionsCollection interfaces are collections derived from the HTMLCollection interface. The HTMLAllCollection interface is a collection, but is not so derived.

2.5.2.1 The HTMLAllCollection interface

The HTMLAllCollection interface is used for the legacy document.all attribute. It operates similarly to HTMLCollection; the main differences are that it allows a staggering variety of different (ab)uses of its methods to all end up returning something, and that it can be called as a function as an alternative to property access.

All HTMLAllCollection objects are rooted at a Document and have a filter that matches all elements, so the elements represented by the collection of an HTMLAllCollection object consist of all the descendant elements of the root Document.

Objects that implement the HTMLAllCollection interface have several unusual behaviors, due of the fact that they have an [[IsHTMLDDA]] internal slot:

These special behaviors are motivated by a desire for compatibility with two classes of legacy content: one that uses the presence of document.all as a way to detect legacy user agents, and one that only supports those legacy user agents and uses the document.all object without testing for its presence first. [JAVASCRIPT]

2.5.2.2 The HTMLFormControlsCollection interface

The HTMLFormControlsCollection interface is used for collections of listed elements in form elements.

collection.length

Returns the number of elements in collection.

element = collection.item(index)
element = collection[index]

Returns the item at index index in collection. The items are sorted in tree order.

element = collection.namedItem(name)
radioNodeList = collection.namedItem(name)
element = collection[name]
radioNodeList = collection[name]

Returns the item with ID or name name from collection.

If there are multiple matching items, then a RadioNodeList object containing all those elements is returned.

radioNodeList.value

RadioNodeList/value

Support in all current engines.

Firefox33+Safari7+Chrome21+
Opera?Edge79+
Edge (Legacy)12+Internet Explorer9+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

Returns the value of the first checked radio button represented by radioNodeList.

radioNodeList.value = value

Checks the first first radio button represented by radioNodeList that has value value.

2.5.2.3 The HTMLOptionsCollection interface

HTMLOptionsCollection

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer6+
Firefox Android?Safari iOS1+Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

The HTMLOptionsCollection interface is used for collections of option elements. It is always rooted on a select element and has attributes and methods that manipulate that element's descendants.

collection.length

Returns the number of elements in collection.

collection.length = value

When set to a smaller number than the existing length, truncates the number of option elements in the container corresponding to collection.

When set to a greater number than the existing length, if that number is less than or equal to 100000, adds new blank option elements to the container corresponding to collection.

element = collection.item(index)
element = collection[index]

Returns the item at index index in collection. The items are sorted in tree order.

collection[index] = element

When index is a greater number than the number of items in collection, adds new blank option elements in the corresponding container.

When set to null, removes the item at index index from collection.

When set to an option element, adds or replaces it at index index in collection.

element = collection.namedItem(name)
element = collection[name]

Returns the item with ID or name name from collection.

If there are multiple matching items, then the first is returned.

collection.add(element[, before])

Inserts element before the node given by before.

The before argument can be a number, in which case element is inserted before the item with that number, or an element from collection, in which case element is inserted before that element.

If before is omitted, null, or a number out of range, then element will be added at the end of the list.

Throws a "HierarchyRequestError" DOMException if element is an ancestor of the element into which it is to be inserted.

collection.remove(index)

Removes the item with index index from collection.

collection.selectedIndex

Returns the index of the first selected item, if any, or −1 if there is no selected item.

collection.selectedIndex = index

Changes the selection to the option element at index index in collection.

2.5.3 The DOMStringList interface

DOMStringList

Support in all current engines.

Firefox1+Safari5.1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android3+Samsung Internet?Opera Android12.1+

The DOMStringList interface is a non-fashionable retro way of representing a list of strings.

strings.length

DOMStringList/length

Support in all current engines.

Firefox1+Safari5.1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android37+Samsung Internet?Opera Android12.1+

Returns the number of strings in strings.

strings[index]
strings.item(index)

DOMStringList/item

Support in all current engines.

Firefox1+Safari5.1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android3+Samsung Internet?Opera Android12.1+

Returns the string with index index from strings.

strings.contains(string)

DOMStringList/contains

Support in all current engines.

Firefox1.5+Safari5.1+Chrome1+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android3+Samsung Internet?Opera Android12.1+

Returns true if strings contains string, and false otherwise.