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

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

  1. hello there and thank you for your info – I’ve definitely picked up something new from right here.

    I did however expertise some technical issues using this site, since I experienced to reload the website
    many times previous to I could get it to load properly.
    I had been wondering if your web hosting is OK?
    Not that I am complaining, but slow loading instances times will very frequently affect your placement in google and
    could damage your quality score if advertising and marketing
    with Adwords. Well I’m adding this RSS to my e-mail and can look out for much more
    of your respective intriguing content. Make sure you update this
    again very soon.

    Reply

Leave a Comment