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