A word to understand the difference and usage of innerheight, (document.documentelement,document.body)/Clientheight,offsetheight

Source: Internet
Author: User

To understand these attributes, first understand the difference between body,documentelement

1. Body is the body child node in DOM object, i.e. <body> tag
2. DocumentElement is the node of the whole node tree, that is, the

========================, the following are all nonsense ==================================

Many people think that the body and HTML are the same, judging by the body with the background color, the entire Web document will be followed by color. In fact, this phenomenon does not mean that the body and the HTML node is the same thing, this is caused by inheritance.

We all know that inheritance refers to the child element inherits some of the attributes of the parent element, body as the child node of the HTML, theoretically there is no HTML Inheritance Body property, but there is an exception, HTML inherits the body's Background property, This causes the body to add a background color to the entire HTML followed by discoloration. (You can try to add a height to the body, set the background color, and then set the HTML another background color, see the effect)

Therefore, the new Web page in the case of no content, the body height is equal to 0, as the content increases, the body height increases with it

======================== nonsense over =======================================

Understand the difference between body and HTML to understand innerheight,clientheight,offsetheight, each browser returns different values, the root cause is that the base of the calculation is different :

1, document.body to the BODY element for the calculation of the benchmark

2, document.documentelement with HTML as the benchmark

IE, Opera thinks offsetheight = clientheight + scroll bar + border.
Chrome, FF thinks offsetheight is the actual height of the Web content, can be less than clientheight.
IE knows that version 11 is only modified to be consistent with CHORME,FF

A word to understand the difference and usage of innerheight, (document.documentelement,document.body)/Clientheight,offsetheight

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.