how to find total height of single page page in html

Solutions on MaxInterview for how to find total height of single page page in html by the best coders in the world

showing results for - "how to find total height of single page page in html"
Damon
09 Jul 2020
1function calculateTotalHeightMinusElement(excludeElementClass)
2{
3  // Get all child elements of the body tag
4  var bodyChildren = (document.getElementsByTagName('body')[0]).children;
5
6  var totalHeight = 0;
7
8  // Loop through the selected elements
9  for (var i = 0; i < bodyChildren.length; i++) {
10
11    // Add the height of this element
12    totalHeight = totalHeight + bodyChildren[i].offsetHeight;
13  }
14
15  // Get the height of the element we want to exclude
16  var excludedElementHeight = document.getElementsByClassName(excludeElementClass)[0].offsetHeight;
17
18  // Calculate height minus the excluded element
19  var finalHeight = totalHeight - excludedElementHeight;
20
21  // Display the final height in an alert
22  alert("Total height: " + finalHeight);
23}
24
25document.addEventListener("DOMContentLoaded", function(event) {
26
27  // Pass in the class name of the element you want to minus from the height calculation
28  calculateTotalHeightMinusElement("myDivClass");
29});
30