function domcomb (oparent,ocallback){
if(oparent.haschildnodes()){
for (var onode = oparent.firstchild; onode; onode = onode.nextsibling){
domcomb (onode,ocallback);
}
}
ocallback.call(oparent);
}
//sample usage
function printcontent(){
if (this.nodevalue){ console.log(this.nodevalue)}
}
onload = function(){
domcomb(document.body, printcontent);
};
The following function recursively cycles all child nodes of a node and executes a callback function upon them (and upon the parent node itself).
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.