<!DOCTYPE HTML><HTML><HeadLang= "en"> <MetaCharSet= "UTF-8"> <title></title></Head><Body><DivID= "Wrap"> <PID= "P">Test</P> <DivID= "Div1"> <P><spanID= "span">Text</span></P> </Div> <DivID= "Div2"></Div> <!--Notes - <ahref="">Link</a></Div></Body></HTML><Script> varWrap=document.getElementById ("Wrap"); varDiv1=document.getElementById ("Div1"); varDiv2=document.getElementById ("Div2"); vara=document.getElementById ("a"); varP=document.getElementById ("P"); varspan=document.getElementById ("span"); //number of child nodes found functionGetchild (obj) {vararr=[]; for(varI=0; I<Obj.childnodes.length;i++){ if(!(Obj.childnodes[i].nodetype==3 &&Obj.childnodes[i].nodevalue.trim ()=="") {Arr.push (obj.childnodes[i]); } } returnarr; } alert (Getchild (wrap). length); //find the first child node functionGetfirstchild (obj) {varFirstChild=Obj.firstchild; while(Firstchild.nodetype==3 &&Firstchild.nodeValue.trim ()=="") {FirstChild=firstchild.nextsibling; } returnFirstChild; } alert (Getfirstchild (Wrap). NodeName); //find the last child node functionGetlastchild (obj) {varLastChild=Obj.lastchild; while(Lastchild.nodetype==3 &&Lastchild.nodeValue.trim ()=="") {LastChild=lastchild.previoussibling; } returnLastChild; } alert (Getlastchild (Wrap). NodeName);</Script>
Resolving node compatibility issues