S
samuelberthelot
Hi,
I'm trying to write a recursive fucntion that takes as parameters a
html div and an id. I have to recurse through all the children and
sub-children of the div and find the one that matches the id.
I have the following but it doesn't work well (algorighm issue) :
var cn = null;
function getChildElement(parent, childID){
for (var i=0; i<parent.childNodes.length; i++){
cn = parent.childNodes;
if(cn.getAttribute){
if(cn.getAttribute("id").toLowerCase().indexOf(childID.toLowerCase()) >
-1 ){
return cn;
}else{
return getChildElement(parent.childNodes, childID);
}
}
}
return cn;
}
Can you help please ?
I'm trying to write a recursive fucntion that takes as parameters a
html div and an id. I have to recurse through all the children and
sub-children of the div and find the one that matches the id.
I have the following but it doesn't work well (algorighm issue) :
var cn = null;
function getChildElement(parent, childID){
for (var i=0; i<parent.childNodes.length; i++){
cn = parent.childNodes;
if(cn.getAttribute){
if(cn.getAttribute("id").toLowerCase().indexOf(childID.toLowerCase()) >
-1 ){
return cn;
}else{
return getChildElement(parent.childNodes, childID);
}
}
}
return cn;
}
Can you help please ?