Name
NodeList: a read-only array of nodes — DOM Level 1 Core: Object → NodeList
Properties
-
readonly unsigned long length The number of nodes in the array.
Methods
-
item() Returns the specified element of the array.
Description
The NodeList interface defines a read-only, ordered list (i.e., an array) of
Node objects. The length property
specifies how many nodes are in the list, and the item( ) method allows you to obtain the
node at a specified position in the list. The elements of a NodeList
are always valid Node objects: NodeLists never contain null elements.
In JavaScript, NodeList objects behave like JavaScript arrays,
and you can query an element from the list using square-bracket
array notation instead of calling the item(
) method. However, you cannot assign new nodes to a
NodeList using square brackets. Since it is always easier to think
of a NodeList object as a read-only JavaScript array, this book uses
the notation Element[] or
Node[] (i.e., an Element array or
Node array) instead of NodeList. The methods Document.getElementsByTagName( ), Element.getElementsByTagName( ), and
HTMLDocument.getElementsByName( )
are all documented in this book as returning a Element[] instead of a NodeList object.
Similarly, the childNodes
property of the Node object is technically a NodeList object, but
the Node reference page defines
it as a Node[], and the property
itself is usually referred to as “the childNodes[] array.”
Note that NodeList objects are live: they are not static snapshots but ...
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