This is a script I have on my page and for some reason I get this error in the console. Here is the error. "Uncaught SyntaxError: Unexpected token ) "
!function ($) {
//=================================== scroll ===================================//
$body.scrollspy({
target: '#navbar-main',
offset: navHeight
});
$window.on('load', function () {
$body.scrollspy('refresh');
});
$('#navbar-main [href=#]').click(function (e) {
e.preventDefault();
});
});
dumbass
27.2k4 gold badges43 silver badges77 bronze badges
2 Answers 2
!function ($) {
});
is a strange pattern to use, and it's not valid, it should be
jQuery(function($) {
});
If you're trying to create a DOM ready handler.
If you just need an IIFE you could do
!function($){
}(jQuery);
which looks like what you're trying to use here ?
answered May 6, 2014 at 20:55
adeneo
319k29 gold badges410 silver badges392 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Don't write this:
!function ($) {
});
Use this :
$(function() {
});
or this
$(document).ready(function() {
});
If you want to hide all code in anonymous function , the syntax is as following:
(function($) {
$body.scrollspy({
target: '#navbar-main',
offset: navHeight
});
$window.on('load', function () {
$body.scrollspy('refresh');
});
$('#navbar-main [href=#]').click(function (e) {
e.preventDefault();
});
})(jQuery);
answered May 6, 2014 at 20:56
Abdennour TOUMI
94.6k42 gold badges271 silver badges274 bronze badges
1 Comment
user3546263
its saying Uncaught ReferenceError: $body is not defined
lang-js
)at the end