-1

A year ago I wrote several projects with jQuery that were working fine but I was looking at my portfolio and now they are broken. In the ide the message I see is

$ is not defined, please fix or add /*global $*/

I've used chrome debugger network to know that jquery.min.js is loading correctly and it is loaded first in the html file. Can anyone tell me what has changed that $ wouldn't be recognized any longer.

External JS file(example of functions using JQuery with eslint only on $)

function updateDisplay(item){
  $('.panel-body').html('<p class="pull-right">' + item + '</p>');
}

$( "button" ).click(function() {
     $( this ).removeClass('button[focus]');
  getId();
});
Rawle Juglal
  • 395
  • 4
  • 17
  • 1
    Where/How are you loading jQuery? – j08691 Feb 16 '17 at 21:44
  • 1
    what is the source of the message ? eslint or jshint ? if you don't see any error thrown in chrome's console then I suspect your linter is wrong :) – niceman Feb 16 '17 at 21:49
  • @j08691 I did a bower install of jquery. The path is correct because chrome network shows it retrieved that file. – Rawle Juglal Feb 17 '17 at 01:34
  • @niceman I believe it is eslint because I use c9.io. Sorry I mispoke earlier. I looked it up since I assumed it was jshint but it was not. The console doesn't throw any errors. But these projects had relied on jquery for dom manipulation and had worked in the past but now that I've come back to look at them they are broke and that is the only warning I see when looking at the file. – Rawle Juglal Feb 17 '17 at 01:34

2 Answers2

0

Try to replace "$" to "jQuery"

function updateDisplay(item){
  jQuery('.panel-body').html('<p class="pull-right">' + item + '</p>');
}

jQuery( "button" ).click(function() {
    jQuery( this ).removeClass('button[focus]');
 getId();
});
0

As an update to close this question. While I can not say why ESLint creates the warning that $ is not defined. It was not what was breaking the projects. Since my question assumed that '$' was the issue I will close this. But others looking for more information might check out this stackoverflow question that had a lot of information JQuery - $ is not defined

Community
  • 1
  • 1
Rawle Juglal
  • 395
  • 4
  • 17