Currently, I am facing a challenge with resizing a div with the id="test"
. My goal is to adjust the size of the div based on the height of the browser window subtracting 80px so that the element fits perfectly within the visible space without requiring scrolling. Here is the JavaScript code I have been using:
let calculatedHeight = document.body.clientHeight - 80;
let targetElement = document.getElementById("test");
targetElement.style.height = calculatedHeight + "px";
While setting the height directly like this works:
myElement.style.height = "600px";
, when trying to calculate it dynamically using document.body.clientHeight;
, the issue arises because it returns a value without the "px" unit.