I want to get the height of an element and pass it into a css variable. The issue im having is when i try to pass that number into the navHeight variable it ends up returning as undefined.
<script>
let navHeightTest = document.getElementById("navbar").offsetHeight;
console.log(navHeightTest); // Returns the nav height as a number
let navHeight = Document.documentElement.style.setProperty('--nav-height', navHeightTest);
console.log(`Nav Height=${navHeight}`); // Returns undefined
</script>
CSS
:root {
--nav-height: 101px; /* Default Fallback Value */
}
.dynamic-margin {
margin-top: calc(var(--nav-height) + 2.5rem) !important;
}