MyBB Community Forums

Full Version: Uncaught TypeError: Cannot read property 'top' of undefined
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

Receiving one error:
Quote:Uncaught TypeError: Cannot read property 'top' of undefined
    at (index):115
    at dispatch (jquery.js?ver=1813:1)
    at r.handle (jquery.js?ver=1813:1)

When inspecting where this issue lies (via index page, which changes with each page as it is in the header) it is the code related to the sticky navigation. Hoping to see if anyone has any ideas what the fix for this could be.

When clicking at (index):115 this is what it is saying is an issue:
<script>
$(document).ready(function() {
    var s = $("#mainmenu");
    var pos = s.position();                    
    $(window).scroll(function() {
        var windowpos = $(window).scrollTop();
        
        if (windowpos >= pos.top) {
            s.addClass("stick");
        } else {
            s.removeClass("stick"); 
        }
    });
});
</script>
Specifically THIS line:
if (windowpos >= pos.top) {

Thanks,
iso
https://fim-rpg.net/
Hi,

after looking to the code, the problem is the missing ID of the div "mainmenu".

s is:
var s = $("#mainmenu");

But there is no div with that ID in all the index.

And when you declare pos:
var pos = s.position();

it's based in s, and s it's not well declared before.

And of course, when you try to "use" the pos variable, it'll fail.
(2018-10-31, 12:43 PM)NoRules Wrote: [ -> ]Hi,

after looking to the code, the problem is the missing ID of the div "mainmenu".

s is:
var s = $("#mainmenu");

But there is no div with that ID in all the index.

And when you declare pos:
var pos = s.position();

it's based in s, and s it's not well declared before.

And of course, when you try to "use" the pos variable, it'll fail.

Thank you NoRules, I will pass this information on. Smile
(2018-10-31, 09:05 PM)isoldehn Wrote: [ -> ]
(2018-10-31, 12:43 PM)NoRules Wrote: [ -> ]Hi,

after looking to the code, the problem is the missing ID of the div "mainmenu".

s is:
var s = $("#mainmenu");

But there is no div with that ID in all the index.

And when you declare pos:
var pos = s.position();

it's based in s, and s it's not well declared before.

And of course, when you try to "use" the pos variable, it'll fail.

Thank you NoRules, I will pass this information on. Smile

Hi. Is this problem solved? Becouse I have this kind of problem. 
What about PHP version? I am running 7.3.