Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
651 views
in Technique[技术] by (71.8m points)

javascript - difference between document.documentElement.clientHeight and document.body.clientHeight

What is the difference between document.documentElement.clientHeight and document.body.clientHeight? Are the return values consistent across all web browsers or does each evaluate them differently?

In my particular case, the documentElement seems to have a smaller height than the body element, which does not make sense. Why does this happen?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The document.documentElement property gives you the html element, while the document.body property gives you the body element.

The window.innerHeight property returns the height of the window rather than the height of the content.

Different browsers will give you different values for the size of those elements, and the same browser may give you different values depending on whether the page is rendered in Quirks Mode or Standards Compliance Mode, and whether you are using HTML or XHTML. The html element can either represent the window, or the entire page. The body element can either be the same size as the html element, or the size of the content in the page.

The html and body elements are "magical" elements that doesn't exist in the same way as other elements. In XHTML they were changed so that they work more like real elements, but there are still some things that are "magic". For example, the body element doesn't have a background on it's own, instead the html and body share the same background, and it always covers the entire window even if the body element doesn't.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...