Copy codeThe Code is as follows: -- The documentElement attribute returns the root node of the document.
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
<Script type = "text/javascript">
Function shownode (){
Var ohtml = document.doc umentElement;
// Alert (ohtml. nodeName );
// Alert (ohtml. childNodes. length );
// Alert (ohtml. childNodes [1]. nodeName); // get the body
// Var obody = ohtml. childNodes [1]; // locate the div layer by layer
Var obody = ohtml. lastChild; // get the last child node of ohtml quickly
// Alert (obody. childNodes [0]. nodeName );
// Alert (obody. parentNode. nodeName); // locate the desired parent node based on the child node
// Alert (obody. previussibling. nodeName );
Var ohead = ohtml. childNodes [0];
// Alert (ohead. nextSibling. nodeName );
}
</Script>
</Head>
// If there is a space between the body and the div, or there is a space between each layer, the result will be affected.
<Body> <div id = "div1"> Layer 2 </div> <div id = "div2"> </div>
<Div> Layer 3 </div>
<Div>
Layer-4 <input id = "Button1" type = "button" value = "display node" onclick = "shownode ();"/> </div>
</Body>
</Html>