Forum Moderators: open

Message Too Old, No Replies

is getElementsByTagName() sorted?

In order that they appear on page?

         

ari11210

3:17 pm on Oct 27, 2004 (gmt 0)

10+ Year Member



Hello all,
If I have 3 iframes on my page and make a call like this:
var elements = document.getElementsByTagName("iframe");

would the 'elements' list be sorted in the order that the iframes appear on my page? Can I be guaranteed that they wont be in a random order? I would like to loop through them, but I need to know what order they come back, and I dont want to test this in every browser.
Does anyone know?

Thanks for your help
Aaron

Bernard Marx

6:23 pm on Oct 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes. The method returns a NodeList, which is an ordered collection of elements.
The numerical indexing will be in source order.
Can't find the particulars to back that up, but I'm sure it's true.