Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSLint - Undeclared 'jQuery' warning

I am trying to make the following jQuery code JSLint compliant.

(function ($) {
   "use strict";
    $('.addition').click(function () {
        $('.textbox:last,.addition:last,.subtraction:last,.replace:last').clone(true).appendTo('.replace:last');
        $('.textbox:last').val("");
        $('.addition:not(:last),.subtraction:not(:last)').attr('disabled','true');
    });

    $('.subtraction').click(function () {

        if($('.replace').length === 1) {
            $('.subtraction').click(function (event) {
                event.preventDefault();
            });
        } else {
            $('.textbox:last,.addition:last,.subtraction:last,.replace:last').remove();
            $('.addition:last,.subtraction:last').removeAttr('disabled');
        }   
    });     
}(jQuery));

My code is working fine. I am just trying to clear the JSLint warnings. I do not understand why JSLint is giving me an undeclared 'jQuery' warning on line }(jQuery)); (last line).

UPDATE
Declaring jQuery as a global variable has cleared the warning.

like image 330
user3421311 Avatar asked May 30 '15 05:05

user3421311


2 Answers

If you're using jslint.com, you'll need to add jQuery to Global variables under options

like image 161
Hicham El Hammouchi Avatar answered Nov 15 '22 21:11

Hicham El Hammouchi


If you're using jslint.com, you need to replace 1st line of your code. you need to add "global jQuery" as a comment line. See here..

replace: (function ($) {

by using: /*global jQuery */
jQuery(function ($) { .....

All the Best.
Puspendu Mondal

like image 34
Puspendu Mondal Avatar answered Nov 15 '22 20:11

Puspendu Mondal