How to find window size (from a website) through javascript in a function, then hide/show elements depending on the size?

I’ve been trying to find many solutions to this, and while I have found many examples that show how to hide/show elements, and how to adjust the css of the website, I simply cannot get something to disappear. (Forgot to add, it is the button for the sidebar) I am trying to create a sidebar, that when the width of the window is less than 1000px, it appears on the left side of the screen (in the header section). If it is larger then it should not be there. The only solution I’ve managed to work was adding !important after a @media query. However, I have seen that this is not the optimal solution. I’ve gone through tons of material but I simply cannot understand or find the solution. I have a minimum understanding of javasript coding, so it’s been rather difficult to say the least.

This is the html code

This is the css code

This is the javascript code

1 thought on “How to find window size (from a website) through javascript in a function, then hide/show elements depending on the size?”

Leave a Comment