Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,982
    Thanks
    120
    Thanked 76 Times in 76 Posts

    getElementsByTagName sort order ?

    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 ?

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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?
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,982
    Thanks
    120
    Thanked 76 Times in 76 Posts
    like this:
    Code:
      var tags = mDiv.getElementsByTagName('div'); 
      ...
      tags[i].style.left = '30px'

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •