Search code examples
javascriptjqueryadobe-brackets

'$' was used before it was defined .hover


I'm trying to get a background gif to play when I hover over a link, and reset and play as you hover over it again.

It works exactly as I want it in this jsFiddle.

When I write my code up in Brackets I get this warning -> $' was used before it was defined. $("#hover").hover(function () {

I have included the Javascript in the head of my HTML like:

<head>
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="main.js"></script>

<head>

The HTML, CSS and JavaScript are the same as in the jsFiddle.

Checked in browser also, doesn't work. i get this warning ---> imain.js:10 Uncaught ReferenceError: $ is not defined at main.js:10 My page in its entirety can be seen here. jepen84.github.io/github.io


Solution

  • You get the error because jQuery does not load.

    To load jQuery, you used: <script type="text/jquery" src="jquery-3.2.1.js"></script>

    jQuery is not a programming language. It's solely a javascript library providing some convenient features.

    In your <script>-tag, change type="text/jquery" to type="text/javascript" and it will load the file.