The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript remove class on resize w/ JS (not Jquery)

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #278573

    I want to remove a class that stacks menu items, after a hamburger-icon has been clicked. Then, when the window is resized over 500px (or so) the items should be floated again.

    I have that menu-open/close-thing running, but not the resize function.

    I guess, I need an event listener that listens to ”window.resize”, then need to get something like 500px in there with something like ”innerWidth” and then need to do something like ”myElement.classList.remove(”my-class”)”. But I just don’t get the syntax together.

    Please take a look at my Codepen


    Give this a try instead:

    window.addEventListener("resize", function() {
      if (window.innerWidth < 500) resize.classList.remove("nav--is-open");

    It’s not the nav that resizes but the screen itself.


    Ahhh, I get it! Thank you so much!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.