Document.documentelement some skills of using _javascript

Source: Internet
Author: User
Copy Code code as follows:

The--documentelement property returns the root node of the document.
<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);
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>
Layer fourth <input id= "Button1" type= button "value=" shows node "onclick=" Shownode (); " /></div>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.