Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

NodeList

NodeList objects are collections of nodes, usually returned by properties such as Node.childNodes and methods such as document.querySelectorAll().

Properties

isEmpty

Returns true if the NodeList contains no nodes, false otherwise.

Methods

item(index: number)

Returns the node at the specified index in the NodeList.

NameTypeDescription
indexnumberThe zero-based index of the node to retrieve
Returns

Node | null - The node at the specified index, or null if the index is out of bounds

forEach(looper: function)

Executes a function for each node in the NodeList.

NameTypeDescription
looperfunctionThe function to execute for each node. Receives the node as its argument.

plus(nodes: NodeList)

Returns a new NodeList containing all nodes from this list plus the nodes from another NodeList. The original NodeLists are not modified.

NameTypeDescription
nodesNodeListThe NodeList to combine with this one
Returns

NodeList - A new NodeList containing all nodes from both lists

appending(nodes: NodeList)

Returns a new NodeList with the specified nodes appended to the end of this list. The original NodeList is not modified.

NameTypeDescription
nodesNodeListThe NodeList to append to this one
Returns

NodeList - A new NodeList with the nodes appended

prepending(nodes: NodeList)

Returns a new NodeList with the specified nodes prepended to the beginning of this list. The original NodeList is not modified.

NameTypeDescription
nodesNodeListThe NodeList to prepend to this one
Returns

NodeList - A new NodeList with the nodes prepended

filter(predicate: function | string)

Returns a new NodeList containing only the nodes that pass the test implemented by the predicate function. The original NodeList is not modified.

NameTypeDescription
predicatefunction | stringA function that tests each node, or a CSS selector string
Returns

NodeList - A new NodeList containing only the nodes that pass the test

toArray()

Returns a new Array containing the nodes in the NodeList.

Returns

Array - A plain array of the nodes in this list

map(mapper: function)

Returns a new Array containing the results of applying the mapper function to each node in the NodeList.

NameTypeDescription
mapperfunctionA function that transforms each node into a new value
Returns

Array - A new array containing the transformed values

apply(mapper: function)

Applies the mapper function to each node in the NodeList, with each node as the 'this' context. The original NodeList is returned for chaining.

NameTypeDescription
mapperfunctionA function to apply to each node
Returns

NodeList - The current NodeList for method chaining

reduce(accumulator: function, initialValue: *)

Reduces the NodeList to a single value by applying an accumulator function to each node. The accumulator function receives the previous result and the current node.

NameTypeDescription
accumulatorfunctionA function that combines the previous result with the current node
initialValue*The initial value to start the reduction with
Returns

* - The final reduced value

last()

Returns the last node in the NodeList, or null if the list is empty.

Returns

Node | null - The last node in the list, or null if empty

first(count?: number)

Returns the first node (no arg) or the first count nodes as a NodeList (ADR-215 W1-G).

NameTypeDescription
count Optionalnumber
Returns

Node | NodeList | null

topMost(count: number)

Returns a new StaticNodeList with the last count nodes (the top of a pile). ADR-215 W1-G canonical name for this.

NameTypeDescription
countnumber
Returns NodeList

take(count: number)

NameTypeDescription
countnumber
Returns NodeList