I want to display a container div if the device has a special width. I made a simple if condition and it works well.
I wanted to add a second function to my code, and the function was not called. After checking, I saw that the code stops after document.getElementyById-Code.
If a warning ("Hello World") is called in an if condition before getElementById, it is called. If it is called in an if condition after getElementById, it is no longer called.
Why is progress stuck there?
Console output: [Error] TypeError: null is not an object (evaluation is "document.getElementById (" whitecontainer "). Style ') setHeightandWidth (-Link deleted-, line 402) onresize (-Link deleted-, line 382)
but the object cannot be null because changing the style does work, it just gets stuck after changing the size.
Thanks for the help!
function setHeightandWidth() { var body = document.body, html = document.documentElement; var height = (Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight) - 75 - 248); var width = document.body.clientWidth; if (width < 1199) { document.getElementById("whitecontainer").style.display = "none"; alert("Hello World!"); } if (width >= 1199) { width = 1140; document.getElementById("whitecontainer").style.display = "inherit"; } var white_container = document.getElementById("whitecontainer"); white_container.style.height = height + "px"; white_container.style.width = width + "px"; }
source share