View Full Version : Ignoring TEXT_NODEs; Is this logical?
08-21-2004, 08:43 AM
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?
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.
08-21-2004, 11:34 PM
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...
08-27-2004, 12:40 AM
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.
08-27-2004, 04:11 AM
I see the difference now, after comparing the lengths of each collection: childNodes doesn't include item.childNodes...
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.