I am trying to walk the Child nodes and am using the code:
var nodes = document.forms[0].childNodes;
alert("nodes = " + nodes + " nodes.length = " + nodes.length);
for (var i=0; i < nodes.length; ++i)
{
alert("Inside for loop - i = " + i);
alert("id: = " + nodes.id);
alert("tag: " + node[i].tagName);
}
alert("length = " + document.addForm.length);
From the first alert I get:
nodes = [object] nodes.length = 16
From the second alert I get:
Inside for loop - i = 0
From the 3rd alert I get:
id: = undefined
It goes no farther from here because the id is undefined.
Why is that?
What I am trying to do is find out the tag names and types as well ids
(haven't got the type there yet).
If I tak out the alert("tag... out I will get all the nodes as undefined.
What am I doing wrong here?
Thanks,
Tom
bruce barker - 07 Sep 2007 06:12 GMT
try spelling nodes correct and using indexer:
var nodes = document.forms[0].childNodes;
for (var i=0; i < nodes.length; ++i)
{
alert("Inside for loop - i = " + i);
alert("id: = " + nodes[i].id);
alert("tag: " + nodes[i].tagName);
}
note: id may not be defined if one doesn't exist. you can nodeName in
place of tagName. this will only give immediate childNodes.
-- bruce (sqlwork.com)
> I am trying to walk the Child nodes and am using the code:
>
[quoted text clipped - 34 lines]
>
> Tom
tshad - 10 Sep 2007 16:42 GMT
> try spelling nodes correct and using indexer:
>
[quoted text clipped - 8 lines]
> note: id may not be defined if one doesn't exist. you can nodeName in
> place of tagName. this will only give immediate childNodes.
That fixed it.
What do you mean by "immediate" childNodes?
Thanks,
Tom
> -- bruce (sqlwork.com)
>
[quoted text clipped - 36 lines]
>>
>> Tom
Kevin Spencer - 07 Sep 2007 12:32 GMT
Depending on which browser you're using, text nodes may be identified as
nodes (Mozilla), or not (IE). So, you will have some nodes that indeed have
no id assigned.

Signature
HTH,
Kevin Spencer
Microsoft MVP
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
>I am trying to walk the Child nodes and am using the code:
>
[quoted text clipped - 34 lines]
>
> Tom