Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anonymous Function Error: $ is not defined

Google Developer Tools is displaying the following error when my PHP page uses the content from a javascript file (my_scripts.js):

"Uncaught ReferenceError: $ is not defined scripts.js:1 (anonymous function)"

Content of my_scripts.js

$('a.button').click(function(){ 
    window.location.href = "another_page.php";         
});

The page and the script work as required. Clicking the element links to the requested page, but the error is there.

1) What causes the error? 2) Can it or should it be ignored?

like image 885
Architect Avatar asked Dec 24 '22 23:12

Architect


1 Answers

1) It looks like your problem is that jQuery haven't been loaded.

Make sure you load jQuery before scripts.js.

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head> 

2) Errors should never be ignored.

like image 75
kopa Avatar answered Dec 27 '22 13:12

kopa