The following JS:
(function() {
"use strict";
$("#target").click(function(){
console.log("clicked");
});
}());
Yields:
test.js: line 5, col 3, '$' is not defined.
When linted using JSHint 0.5.5. Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are using a relatively recent version of JSHint, the generally preferred approach is to create a .jshintrc file in the root of your project, and put this config in it:
This declares to JSHint that $ is a global variable, and the false indicates that it should not be overridden.
The .jshintrc file was not supported in really old versions of JSHint (such as v0.5.5 like the original question in 2012). If you cannot or do not want to use the .jshintrc file, you can add this at the top of the script file:
There is also a shorthand “jquery” jshint option as seen on the JSHint options page..