I apologize if this question has already been given. I tried to find solutions, but could not find the appropriate code. I'm still new to jQuery.
I have two different types of sticky menus for two different pages. Here is the code for both.
$(document).ready(function () { var contentNav = $('.content-nav').offset().top; var stickyNav = function () { var scrollTop = $(window).scrollTop(); if (scrollTop > contentNav) { $('.content-nav').addClass('content-nav-sticky'); } else {; $('.content-nav').removeClass('content-nav-sticky') } }; stickyNav(); $(window).scroll(function () { stickyNav(); }); }); $(document).ready(function () { var stickyNavTop = $('.nav-map').offset().top;
My problem is that the code for the sticky side menu below does not work, because the second line of code is var contentNav = $('.content-nav').offset().top; raises an error that reads "Uncaught TypeError: it is not possible to read the top property from undefined". Actually, no other jQuery code below this second line works at all if they are not located above it.
After some research, I think the problem is that $('.content-nav').offset().top cannot find the specified selector because it is on a different page. If so, I cannot find a solution.
javascript jquery dom html css
edubba Nov 24 '13 at 13:35 2013-11-24 13:35
source share