I know that live NodeList returned by getElementsByTagName preserves the document order of elements.
Is it true for getElementsdByClassName, getElementsByName and querySelectorAll methods?
does these method also preserve the document order?
Any DOM/HTML5 W3C standard link would be appreciated.
Yes. All of them are in document order / tree order.
getElementsByName (DOM Level-2-HTML) returns a NodeListquerySelectorAll (Selectors API) returns a NodeList "in document order"getElementsByTagName (DOM) returns a HTMLCollectiongetElementsByClassName (DOM) returns a HTMLCollectionHTMLCollections and NodeLists are both specified to have
the elements are sorted in tree order.
when those are accessed via indizes. It does not really matter whether the NodeList is live or not (though of course the actual document order could change in contrast to the one preserved in the static NodeList).
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