The DOM method getChildNodes()
returns a NodeList
of the children of the current Node
. Whilst a NodeList
is ordered, is the list guaranteed to be in document order?
For example, given <a><b/><c/><d/></a>
is a.getChildNodes()
guaranteed to return a NodeList
with b
, c
and d
in that order?
The javadoc isn't clear on this.
The NodeList object represents an ordered list of nodes.
A NodeList is a collection of document nodes (element nodes, attribute nodes, and text nodes). HTMLCollection items can be accessed by their name, id, or index number. NodeList items can only be accessed by their index number. An HTMLCollection is always a live collection.
isSameNode(Node other) This method returns whether current node is the same node as the given one.
Note: Although NodeList is not an Array , it is possible to iterate over it with forEach() . It can also be converted to a real Array using Array. from() .
In my experience, yes. The DOM spec isn't any clearer. If you're paranoid, try something like
current = node.firstChild;
while(null != current) {
...
current = current.nextSibling;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With