Abs
Abs

Reputation: 57916

$ is not defined: What does this mean?

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.

Upvotes: 3

Views: 25962

Answers (11)

karthik339
karthik339

Reputation: 309

Try adding this in your JS file

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

Upvotes: 0

pif
pif

Reputation: 41

Try to include the JQuery js before your custom Js file on html:

<script src="../../Scripts/jquery-1.8.2.min.js" type="text/javascript" ></script>
<script src="../../Scripts/___your js___ .js" type="text/javascript"></script>

Upvotes: 4

Anonymous
Anonymous

Reputation: 11

This sounds like a permissions issue. Look to make sure that your files have access to that .js file. They should be 777.

Upvotes: 1

Ali
Ali

Reputation: 8100

Every time I got this error, it was either because 1- reference to the jquery.js was wrong ( wrong path) 2- wrong file name ...

So correct the path or spellings or file names/folder names etc

Upvotes: 0

Hallgeir Engen
Hallgeir Engen

Reputation: 971

This problem might also be to security issue. If you have authentication on your website, for example

<authentication mode="Forms">   
<forms loginUrl="file1.aspx" defaultUrl="file2.aspx"/>
</authentication>
<authorization>
<deny users="?"/> 
</authorization>

Then you must exclude your script folder from this security settings with the following in web.config.

<location path="Scripts">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>

Upvotes: 0

lo_fye
lo_fye

Reputation: 6840

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>

Upvotes: 0

Peter Delaney
Peter Delaney

Reputation: 5378

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

Upvotes: 0

Cerebrus
Cerebrus

Reputation: 25775

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

Upvotes: 2

Brian Campbell
Brian Campbell

Reputation: 332756

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

Upvotes: 1

Gordon Gustafson
Gordon Gustafson

Reputation: 41209

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.

Upvotes: 18

Andrew Hare
Andrew Hare

Reputation: 351466

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"></script>

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.

Upvotes: 12

Related Questions