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?
The
document.documentElementproperty gives you thehtmlelement, while thedocument.bodyproperty gives you thebodyelement.The
window.innerHeightproperty 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
htmlelement can either represent the window, or the entire page. Thebodyelement can either be the same size as thehtmlelement, or the size of the content in the page.The
htmlandbodyelements 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, thebodyelement doesn’t have a background on it’s own, instead thehtmlandbodyshare the same background, and it always covers the entire window even if thebodyelement doesn’t.