Differences between document.doc umentElement and document. body _ javascript skills

Source: Internet
Author: User
Body is the body subnode In the DOM object, that is, the body tag. documentElement is the root node root of the entire node tree. For details, see this article. If you are interested, see the following differences:

Body is the body subnode In the DOM object, that isTag;
DocumentElement is the root node root of the entire node tree, that isTag;

In BackCompat mode, if no DTD is used:

The Code is as follows:


Document.doc umentElement. clientHeight = 0document. body. clientHeight = 618


In the standard mode of CSS1Compat, when using DTD:

The Code is as follows:


Document.doc umentElement. clientHeight = 618 document. body. clientHeight = 28 (indicating the height of the content)


Therefore, you must pay attention to the size of the browser. You can refer to the following code:

The Code is as follows:


If (document. compatMode = "BackCompat "){
CWidth = document. body. clientWidth;
CHeight = document. body. clientHeight;
SWidth = document. body. scrollWidth;
SHeight = document. body. scrollHeight;
SLeft = document. body. scrollLeft;
STop = document. body. scrollTop;
}
Else {// document. compatMode = "CSS1Compat"
CWidth = document.doc umentElement. clientWidth;
CHeight = document.doc umentElement. clientHeight;
SWidth = document.doc umentElement. scrollWidth;
SHeight = document.doc umentElement. scrollHeight;
SLeft = document.doc umentElement. scrollLeft = 0? Document. body. scrollLeft: document.doc umentElement. scrollLeft;
STop = document.doc umentElement. scrollTop = 0? Document. body. scrollTop: document.doc umentElement. scrollTop;
}

Related Article

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: info-contact@alibabacloud.com 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.