Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialleetrappitt
1,787 PointsjQuery is not defined
Hi I have a problem I just can not resolve. I have a mobile menu which works fine in the browser but only works on smartphone after refreshing the page
I get
Uncaught ReferenceError: jQuery is not defined
Here is the code, and below that is the order in which the scripts load
(function($) {
$.fn.collapsable = function(options) {
return this.each(function() {
var obj = $(this);
var tree = obj.next('.main-menu ul');
obj.click(function(){
if( obj.is(':visible') ){ tree.toggle();}
});
$(window).resize(function(){
if ( $(window).width() <= 800 ){tree.attr('style','');};
});
});
};
})(jQuery);
$(document).ready(function(){
$('.slide-trigger').collapsable();
});
(analytics code loads first top of the page www.google-analytics.com/analytics.js)
rest of the script loads from the footer all inside the body mobile-menu.js relates to the code above.
<script async src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" type="text/javascript"></script>
<script async src="js/mobile-menu.js" type="text/javascript"></script>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script async>(adsbygoogle = window.adsbygoogle || []).push({});</script>
<script async>(adsbygoogle = window.adsbygoogle || []).push({});</script>
<script async>(adsbygoogle = window.adsbygoogle || []).push({});</script>
Its driving me insane as it all works great except for the load on the mobile.
Many Thanks for taking a look.
2 Answers
leetrappitt
1,787 PointsThe answer was to remove async.
leetrappitt
1,787 PointsSorry for the awful formatting.