0

I have the function which adds a class to a div based on window position.

$(window).scroll(function() {
  var scroll = $(window).scrollTop();
  if(scroll >= 300) {
    $("#s-nav").addClass('s-nav-w');
  } else {
    $("#s-nav").removeClass('s-nav-w');
  }
});

I want to add another class to add/remove. I want to add text-w to .main-nav li a class.

2
  • What's stopping you from doing that? Commented Nov 15, 2016 at 5:45
  • I added extra else commands apparently since the given answer works Commented Nov 15, 2016 at 5:54

1 Answer 1

1

May be this will solve your issue

 $(window).scroll(function() {
    var scroll = $(window).scrollTop();
    if (scroll >= 300) {
         $("#s-nav").addClass('s-nav-w');
         $(".main-nav li a").addClass('text-w');
    } else{
         $("#s-nav").removeClass('s-nav-w');
         $(".main-nav li a").removeClass('text-w');
    }
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.