Jordyn
Jordyn

Reputation: 1133

TypeError: pos is undefined error

I'm getting TypeError: pos is undefined on below code.

$(document).ready(function() {
    var s = $("#col-scroll");
    var pos = s.position();                   
    $(window).scroll(function() {
        var windowpos = $(window).scrollTop();

        if (windowpos+60 >= pos.top) {
            s.addClass("col-fixed");
        } else {
            s.removeClass("col-fixed");
        }
    });
});

Code used to work fine. Dont know why it is giving an error. Can someone tell me what is the issue here? Really appropriated your help.

Upvotes: 1

Views: 997

Answers (1)

Franco
Franco

Reputation: 2329

It is telling you that pos in undefined, so are you sure you are addressing this correctly? position() get the current coordinates of the first element in the set of matched elements, relative to the offset parent. So if this can not be found you var s is undefined.

Upvotes: 2

Related Questions