I am trying to get the values of all the child elements from a specific element
[CODE=javascript]
function getnodes(elem)
{
for (i=0; i<elem.childNod es.length; i++)
{
alert(elem.chil dNodes[i].nodeName);
alert(elem.chil dNodes[i].nodeType);
if(elem.childNo des[i].nodeType==1)
{
alert("hello - "+elem.childNod es[i].nodeName);
getnodes(elem.c hildNodes[i]);
}
else if(elem.childNo des[i].nodeType==3)
{
alert("hi text");
}
}
}
window.onload=f unction(){
var node=document.g etElementById(" hello");
var count=0;
while(count<5)
{
node=node.paren tNode;
count++;
}
getnodes(node);
}[/CODE]
this is the html code
[HTML]<div style="padding-left:15px; color:#0f0f0f; background-color:#0099FF"> <strong>hello </strong>
<table>
<tr>
<td bgcolor="#CC996 6"><iframe id="hello" src="http://www.xyz.com"></iframe></td>
</tr>
</table>
</div> [/HTML]
I am getting problems in the code
when i put my code directly in a new page, it is working fine but when i put it in some page, it gave only 2 alerts and completed without errors
the alerts were for tags <strong> then for #text and it completed
it never went to my table element
[CODE=javascript]
function getnodes(elem)
{
for (i=0; i<elem.childNod es.length; i++)
{
alert(elem.chil dNodes[i].nodeName);
alert(elem.chil dNodes[i].nodeType);
if(elem.childNo des[i].nodeType==1)
{
alert("hello - "+elem.childNod es[i].nodeName);
getnodes(elem.c hildNodes[i]);
}
else if(elem.childNo des[i].nodeType==3)
{
alert("hi text");
}
}
}
window.onload=f unction(){
var node=document.g etElementById(" hello");
var count=0;
while(count<5)
{
node=node.paren tNode;
count++;
}
getnodes(node);
}[/CODE]
this is the html code
[HTML]<div style="padding-left:15px; color:#0f0f0f; background-color:#0099FF"> <strong>hello </strong>
<table>
<tr>
<td bgcolor="#CC996 6"><iframe id="hello" src="http://www.xyz.com"></iframe></td>
</tr>
</table>
</div> [/HTML]
I am getting problems in the code
when i put my code directly in a new page, it is working fine but when i put it in some page, it gave only 2 alerts and completed without errors
the alerts were for tags <strong> then for #text and it completed
it never went to my table element
Comment