jQuery adds class, but does not remove

Asked

Viewed 43 times

0

I am using this code to add a class to leave a fixed menu. The problem is that it is not removing the class afterwards. How to proceed?

$(window).on('scroll', function() {
  if ($(this).scrollTop() >= $('nav').offset().top) {
    $('nav:not(.fixo)').addClass('fixo');
  } else {
    $('nav.fixo').removeClass('fixo');
  }
});
  • 1

    Seems to be working fine: https://jsfiddle.net/zo9x5v8e/

  • here he adds the class but does not remove, I do not know why

  • 2

    would be nice if you also post HTML

  • it seems that it works but after assigning the fixed class and scrolling the page up there it no longer works, does not recognize the scrollUp ?

  • put a.log console before the line $('Nav.fixed'). removeClass('fixed'); to find out if at least the code has reached there

  • Puts the HTML... pf.

Show 1 more comment

1 answer

0

I believe you can use $("#id_campo").removeAttr("class");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.