Your javascript code only executes once when it is loaded.
To make the function being called when something happens, you need to attach it to an event listener.
In this case, you may want the panel changed when the screen is resized.
So, attached the function to window.onresize
event listener.
The function will then be triggered when you resize the screen.
The code is as below. (I use body
element as an example instead)
var res=document.querySelector("body");
window.onresize = function () {
var wid = window.innerWidth;
if(wid <= 900){
res.setAttribute("style", "background-color: red;");
}
}
You can drag the screen size to see if the background color changed when width under 900px.
Is this what you want to achieve?