views:

1022

answers:

7

Hello all,

I get a JS error and I can't figure out how to fix it.

When my page loads up, IE7 notifies me of a run time error. In addition, my Firebug on Firefox warns me of an error:

$ is not defined
(?)
[Break on this error] $(document).ready(function() { $("a#sin...Out': 300, 'overlayShow': false }); });

When I go to the lines in question its this:

<script type="text/javascript" src="/templates/magazeen/js/jquery/jquery.dropdown.js"></script>
    <script type="text/javascript">
    $(document).ready(function() { $("a#single_image").fancybox(); $("a#inline").fancybox({ 'hideOnContentClick': false }); $("a.group").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false }); });
    </script>

Any help please.

+10  A: 

Do you have a script reference to jQuery above the script block in question? The reason you are seeing this error is because you are using the jQuery function $ without referencing jQuery itself.

You need to add a script reference to jQuery like this:

<script type="text/javascript" src="/yourJsDir/jQuery.js"></script>

if you have a local copy of jQuery.js. Otherwise you can use Google's hosted version like this:

<script type="text/javascript" 
    src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js"&gt;&lt;/script&gt;

Just make sure that these script references live above the script block in question as that way your jQuery plugin will have $ defined for it.

Andrew Hare
+12  A: 

You may have only included the dropdown part of jQuery, and not the whole thing. Try including just the JQuery.js file, without specification as to what part.

CrazyJugglerDrummer
+1  A: 

You probably need to include the normal jquery.js or jquery.min.js as well.

Brian Campbell
+2  A: 

It appears that your code uses JQuery. Are you sure you have included the JQuery library in the correct location?

Cerebrus
A: 

It means, you should use euro.

stepancheg
Funny but not relevant. :)
Abs
A: 

I had this exact problem yesterday and it was because I did not have the proper reference to the jQuery library.

Peter Delaney
A: 

I was working on a file locally at file:///Users/lo_fye/Desktop/jquery/index.html I was including the scripts with:

<script type="text/javascript" src="/jquery.js"></script>

And I was getting the same error:

$ is not defined

The fix was prepending a period to the script name, like this:

<script type="text/javascript" src="./jquery.js"></script>
lo_fye