...

View Full Version : getElementsByTagName sort order ?



BubikolRamios
10-19-2008, 08:15 AM
1. outerDiv
2. a bunch of inner divs, which are moved around by mouse click
3 whenewer i do outerdiv.getElementsByTagName('div'), they come out in same order

seems to me this works in order as they were originaly added ?

liorean
10-19-2008, 09:31 AM
getElementsByTagName returns a live NodeList. NodeLists sort in ascending depth-first traversal order on the node tree of the document. They should come out in the order they are placed in the DOM at the time of traversal.

Are you actually changing their position in the DOM or are you merely changing their positioning in the layout?

BubikolRamios
10-19-2008, 10:45 AM
like this:


var tags = mDiv.getElementsByTagName('div');
...
tags[i].style.left = '30px'

liorean
10-19-2008, 12:44 PM
Yep, that's a change of it's position in the layout, not it's position in the document tree. A change in the position in the document tree is equivalent to moving it in the source code relative to the other divs.

NodeLists operate on the document tree, not the presentation.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum