I am attempting to utilize Window.innerWidth and load the resulting value into a CSS variable, but it doesn't appear to be functioning correctly. What could I be doing incorrectly?
function myFunction() {
var w = window.innerWidth;
document.documentElement.style
.setProperty('--window', w);}
:root {
--window:0px;
}
div {
height: calc(var(--window) / 2);
background:red;
}
<div></div>