Name
HTMLCollection: array of HTML elements accessible by position or name — DOM Level 2 HTML: Object → HTMLCollection
Properties
-
readonly unsigned long length The number of elements in the collection.
Methods
-
item( ) Returns the element at the specified position in the collection. You can also simply specify the position within array brackets instead of calling this method explicitly.
-
namedItem( ) Returns the element from the collection that has the specified value for its
idornameattribute, ornullif there is no such element. You can also place the element name within array brackets instead of calling this method explicitly.
Description
An HTMLCollection is a collection of HTML elements with
methods that allow you to retrieve an element by its position in the
collection or by its id or
name attribute. In JavaScript,
HTMLCollection objects behave like read-only arrays, and you can use
JavaScript square-bracket notation to index an HTMLCollection by
number or by name instead of calling the item( ) and namedItem( ) methods.
A number of the properties of the HTMLDocument object are
HTMLCollection objects and provide convenient access to document
elements such as forms, images, and links. The Form.elements property and Select.options property are HTMLCollection
objects. The HTMLCollection object also provides a convenient way to traverse the rows
of a Table and the cells of a TableRow.
HTMLCollection objects are read-only: you cannot assign new elements to them, even when using JavaScript ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access