There is a code
$(".main-nav a").click(function() { var scrollId = $(this).attr("href"); change_active($(this), scrollId); scroll_if_anchor(scrollId); return false; }); function change_active(href, scrollId) { console.log(href); href .removeClass("active") .filter("[href=" + scrollId +"]").addClass("active"); } The class is set but not removed from the previous item - a, why?