Question

I would like to remove the class .active of two elements (#information, #content) once the window has been scrolled for 50px. Here's the code how I would like to add the class .active and remove it again - sadly it doesn't work. Maybe somebody can help me?

$("#button").click(function(e) {
    e.preventDefault();
    $("#information, #content").addClass("active");
});
$(window).scroll(function(){
    if ( (!$(window).scrollTop()>50) || (!$("#information").hasClass("active")) )
    {
        $("#content").removeClass("active");
        $("#information").removeClass("active");
    }
});
Was it helpful?

Solution

Try:

$("#button").click(function(e) {
        e.preventDefault();
        $("#information, #content").addClass("active");
    });
    $(window).scroll(function(){
        if($(window).scrollTop()>50) && $("#information").hasClass("active") )
        {
            $("#content").removeClass("active");
            $("#information").removeClass("active");
        }
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top