0

When I run this code error appears

$(document).ready(function(){ $('#menu').click(function(){ $(this).toggleClass('fa-times'); $('.navbar').toggleClass('nav-toggle'); }); $(window).on('scroll load',function(){ $('#menu').removeClass('fa-times'); $('.navbar').removeClass('nav-toggle'); if($(window).scrollTop() > 60){ $('header').addClass('header-active'); }else{ $('header').removeClass('header-active'); } $('section').each(function(){ let top = $(window).scrollTop(); let height = $(this).height(); let offset = $(this).offset().top - 200; let id = $(this).attr('id'); if(top >= offset && top < offset + height){ $('.navbar ul li a').removeClass('active'); $('.navbar').find(`[href="#${id}"]`).addClass('active'); } }); }); }) $ is not defined https://code.sololearn.com/WRKUMDFHOfZO/?ref=app

11th Jan 2022, 7:34 AM
Krish Patel
Krish Patel - avatar
2 Answers
+ 6
Krish Move the jQuery link into the <head> section, after <title>. This happens because jQuery link is at the bottom of document, and your script in JS tab is executed before jQuery is loaded. P.S. Please add jQuery in the tags ☝
11th Jan 2022, 8:06 AM
Ipang
+ 1
OK thanks bro😊
11th Jan 2022, 1:42 PM
Krish Patel
Krish Patel - avatar