JavaScript - Cannot read property 'top' of null
I have function that scrolls to a anchor position in a list

       function snapToAnchor(anchor) {
        $('#divProductScroll').scrollTop(0);
        var offset = $(anchor).offset().top - $('#divProductScroll').offset().top;
        $('#divProductScroll').scrollTop(offset);
        //$('#divProductScroll').animate({ scrollTop: offset }, 250);
    }

but this is giving me error some times

saying **Cannot read property 'top' of null**

I am not so good with JavaScript

Can any one help with this issue?
JavaScript - Cannot read property 'top' of null
===

I have function that scrolls to a anchor position in a list

       function snapToAnchor(anchor) {
        $('#divProductScroll').scrollTop(0);
        var offset = $(anchor).offset().top - $('#divProductScroll').offset().top;
        $('#divProductScroll').scrollTop(offset);
        //$('#divProductScroll').animate({ scrollTop: offset }, 250);
    }

but this is giving me error some times

saying **Cannot read property 'top' of null**

I am not so good with JavaScript

Can any one help with this issue?