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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ignoring TEXT_NODEs; Is this logical?

    Just had a thought about using getElementsByTagName("*") to return only element nodes from relational properties; maybe this would be better than childNodes... what do you think: is there a flaw in such reasoning?
    *this message will self destruct in n-seconds*

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Nope. Often that method is used in scripts. The only gotcha is that it returns children of children, and children of children of children, and so on.

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I thought element.getElementsByTagName("*") would return no more element nodes than element.childNodes (haven't checked, yet); I wonder how the gurus skip over text nodes...
    *this message will self destruct in n-seconds*

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    They are here - ask them.
    THere's two choices, and which you use depends on how the tree structure looks. If the tree structure is flat or at least only mildly nested, you might want to use getElementsByTagName('*') and then check if the parentNode is the correct element.

    If the tree is more than mildly nested (meaning it has perhaps more than one element out of five that contains other elements) your best choice is loop through the childNodes collection and ignore any nodes that have a nodeType value other than 1.
    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

  • #5
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I see the difference now, after comparing the lengths of each collection: childNodes doesn't include item.childNodes...
    *this message will self destruct in n-seconds*


  •  

    Posting Permissions

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