addClass is working in a place but not working in the other place


#1

this code below in jQuery is working for the first addClass functiond but it says addClass is not a function in the second case inside the IF statement
`(document).ready(function(){ 'use strict'; // smooth scroll (‘nav ul li a’).click(function(e){
e.preventDefault();
('body, html').animate({ scrollTop: (’#’+(this).data('scroll')).offset().top }, 1000); //(this).siblings().removeClass(‘active’);
(this).addClass('active'); }); // adding activ class /*(‘nav ul li a’).click(function(e){

});*/
// sync with scroll
$(window).scroll(function(){
    $('div').each(function(){
        if($(window).scrollTop() > $(this).offset().top){
            var linkDat =$('nav a').data('scroll');
            var divid =$(this).attr('id');
            if(linkDat == divid ){
                //linkDat.siblings().removeClass('active');
                linkDat.addClass('active');
            }
        }
    });
});

});`