Reputation: 79
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();
});
});
Upvotes: -1
Views: 68
Reputation: 93531
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);
Upvotes: 2
Reputation: 318342
!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 ?
Upvotes: 3