You need to add eventListener, and you do not need to use getElementsByTagName, because it has only one body tag:
function setWindowHeight(){ var windowHeight = window.innerHeight; document.body.style.height = windowHeight + "px"; console.log(document.body.style.height); } window.addEventListener("resize",setWindowHeight,false);
Or, if you want to use, you can do this:
function setWindowHeight(){ var windowHeight = window.innerHeight; document.getElementsByTagName('body')[0].style.height = windowHeight + "px"; console.log(document.body.style.height);
EDIT (Changed code above): you can check the value in the Firefox console. Open it (CTRL + SHIFT + K) and resize the window, you will see that resizing the event will be triggered when you do this.
source share