1
<html>
<head><title>test</title>

  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
  </script>
  <!-- ERROR IS HERE the jquery is not being loaded -->

  <script type="text/javascript" src="js/jquery.prettyPhoto.js">
  </script>
  <link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" 
      media="screen" charset="utf-8" />
</head>
<body>
  <a title="Despicable Me" rel="prettyPhoto[movies]" 
    href="http://trailers.apple.com/mymovie.mov?width=640&height=360">
    <img src="images/thumbnails/quicktime-logo.gif" alt="Despicable Me" 
    width="50" />
  </a>
  <a title="Despicable Me" rel="prettyPhoto[movies]" 
    href="ai.mov?width=640&height=360">
    <img src="images/thumbnails/quicktime-logo.gif" 
      alt="Despicable Me" width="50" />
  </a>
  <script type="text/javascript" charset="utf-8">
    $(document).ready(function(){
      $("a[rel^='prettyPhoto']").prettyPhoto();
    });
  </script>
</body>
</html>

When I load this html in firefox, the error console returns an error:

jQuery is not defined. 

The html file, js file, and the css file are all in the same folder. What am I doing wrong?

4
  • what the hell is src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" path Commented Oct 15, 2012 at 11:21
  • 2
    check the network tab in chrome to see if jquery is downloading correctly Commented Oct 15, 2012 at 11:21
  • jquery path is wrong. nothing serious, chill Commented Oct 15, 2012 at 11:22
  • 1
    // is ok stackoverflow.com/questions/9646407/… Commented Oct 15, 2012 at 11:22

3 Answers 3

6

I think you run this in local. (Note: not mean localhost, mean you opened the local html file)

If you run in local, then //ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js means file:///ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js

So you need to specify the http://

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

But once you upload your page to the server, it's ok with just //, and this is best practice.

Sign up to request clarification or add additional context in comments.

3 Comments

@wisdom I don't mean localhost, I mean you run the html as local file.
@xdazz My apologies, thought you were just suggesting adding http: like everyone else. After your edit I see what you are saying, accessing it outside of a web server will be using the file: protocol, which isn't suitable for fetching the script.
@GenericJon No problem, I didn't organize my answer well and lead the misunderstanding.
5

Sorry Last Answer was wrong

Try downloading jquery from google and use it from local server like

<script src="jquery.min.js"></script>

AND

If all files are under same directory then when you are appending js/ in front of jquery.prettyPhoto.js and also css/ they should be like

<html>
<head>
<title>test</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.prettyPhoto.js"></script>
<link rel="stylesheet" href="prettyPhoto.css" type="text/css" media="screen"  charset="utf-8" />
</head>
<body>
<a title="Despicable Me" rel="prettyPhoto[movies]" href="http://trailers.apple.com/movies/universal/despicableme/despicableme-tlr1_r640s.mov?width=640&height=360"><img     src="quicktime-logo.gif" alt="Despicable Me" width="50" /></a>
<a title="Despicable Me" rel="prettyPhoto[movies]" href="ai.mov?width=640&height=360"><img src="quicktime-logo.gif" alt="Despicable Me" width="50" /> </a>

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
  $("a[rel^='prettyPhoto']").prettyPhoto();
});
</script>
</body>
</html>

Comments

0

use

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

to get the JQuery file from the google server

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.