Copy Code code as follows:
The--documentelement property returns the root node of the document.
<title></title>
<script type= "Text/javascript" >
function Shownode () {
var ohtml = document.documentelement;
alert (ohtml.nodename);
alert (ohtml.childNodes.length);
alert (ohtml.childnodes[1].nodename); Get body
var obody = ohtml.childnodes[1]; A layer of Find div
var obody = Ohtml.lastchild; Quickly get the last child node of a ohtml
alert (obody.childnodes[0].nodename);
alert (obody.parentNode.nodeName); Find the desired parent node based on child node
alert (obody.previousSibling.nodeName);
var ohead = ohtml.childnodes[0];
alert (ohead.nextSibling.nodeName);
}
</script>
Body if there is a space between the div, or there is a space between each layer, will affect the results obtained
<body><div id= "Div1" > First floor </div> <div id= "Div2" > Second level </div>
<div> third floor </div>
<div>
Layer fourth <input id= "Button1" type= button "value=" shows node "onclick=" Shownode (); " /></div>
</body>