AluminX
12-21-2007, 03:54 PM
Hi,
I've got a problem. I've trying to inspect all of the elements that are into a given div named "myDiv" after some minutes of thinking this is what i came up with.
function launch(){
if(document.getElementById('myDiv')){
var nodes = sPage.document.getElementById('myDiv).childNodes;
for (i=0;i<nodes.length-1 ;i++ )
{
if (nodes[i].hasChildNodes() && nodes[i].nodeType==1)
{
console.innerHTML += '<br />' + nodes[i].nodeName;
searchForChildren(nodes[i]);
}else console.innerHTML += '<br />' + nodes[i].nodeName;
}
}
function searchForChildren(n){
var nodes = n.childNodes;
for (i=0;i<nodes.length-1 ;i++ )
{
if (nodes[i].hasChildNodes() && nodes[i].nodeType==1)
{
console.innerHTML += '<br />' + nodes[i].nodeName;
searchForChildren(nodes[i]);
}else console.innerHTML += '<br />' + nodes[i].nodeName;
}
return;
}
because searchForChildren() is always a scope of itself so are the variables of each instance that are created reseting i to 0 and nodes to the previews one ending up into an infinite loop. I know there must be something i can do to make this thing work. anyone has any idea?
Thanks
I've got a problem. I've trying to inspect all of the elements that are into a given div named "myDiv" after some minutes of thinking this is what i came up with.
function launch(){
if(document.getElementById('myDiv')){
var nodes = sPage.document.getElementById('myDiv).childNodes;
for (i=0;i<nodes.length-1 ;i++ )
{
if (nodes[i].hasChildNodes() && nodes[i].nodeType==1)
{
console.innerHTML += '<br />' + nodes[i].nodeName;
searchForChildren(nodes[i]);
}else console.innerHTML += '<br />' + nodes[i].nodeName;
}
}
function searchForChildren(n){
var nodes = n.childNodes;
for (i=0;i<nodes.length-1 ;i++ )
{
if (nodes[i].hasChildNodes() && nodes[i].nodeType==1)
{
console.innerHTML += '<br />' + nodes[i].nodeName;
searchForChildren(nodes[i]);
}else console.innerHTML += '<br />' + nodes[i].nodeName;
}
return;
}
because searchForChildren() is always a scope of itself so are the variables of each instance that are created reseting i to 0 and nodes to the previews one ending up into an infinite loop. I know there must be something i can do to make this thing work. anyone has any idea?
Thanks