/    Sign up×
Community /Pin to ProfileBookmark

$ or jQuery not defined errors

Hello everyone,

I’m getting 10 (!!!!!) “‘$’ is not defined. (no-undef)” errors in the following code:

[CODE]jQuery(document).ready(function() {

// search funtion in navbar
(function(jQuery) {

$(‘#search-button’).on(‘click’, function(e) {
if ($(‘#search-input-container’).hasClass(‘hdn’)) {
e.preventDefault();
$(‘#search-input-container’).removeClass(‘hdn’)
return false;
}
});

$(‘#hide-search-input-container’).on(‘click’, function(e) {
e.preventDefault();
$(‘#search-input-container’).addClass(‘hdn’)
return false;
});

})(jQuery);

// make the squares match height
$(function() {
$(‘.square’).matchHeight({ byRow: false });
});

});[/CODE]

I have been searching for a solution, but to no avail. The most common causes of and solutions to this error that I checked:
1. load jQuery BEFORE your own scripts: CHECK
2. replace $ by jQuery: CHECK
3. install jQuery migrate: CHECK

But still it’s going berserk over such little code. Does any of you experts has advice on how to analyse this issue?

Thank you very much

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@rootOct 20.2017 — Please note that JQuery is not JavaScript and it goes in the JavaScript Frameworks forum.

*moved*
Copy linkTweet thisAlerts:
@Jeff_MottOct 31.2017 — @Fledermaus [url=https://eslint.org/docs/rules/no-undef]no-undef[/url] isn't a browser error; it's a linting error. Your linter is trying to protect you from misspellings of variable and parameter names or accidental implicit globals. But it can only make these decisions based on the code it *sees*, and it doesn't see jQuery's definition, so it doesn't know that "$" is in fact defined. You'll need to [url=https://eslint.org/docs/user-guide/configuring#specifying-environments]configure[/url] your linter so it assumes jQuery variables are pre-defined.
Copy linkTweet thisAlerts:
@FledermausauthorOct 31.2017 — Hi Jeff Mott,

thanks for the info. A quick search tells me that I have to define a global jQuery var in my main javascript file:

/* global $ */

I'll will try this. Thanks very much !
×

Success!

Help @Fledermaus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...