user3550879 user3550879 - 24 days ago 7
CSS Question

adding additional parameters to a function

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.

Answer

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');
    }
 });