4
<script href="http://code.jquery.com/jquery-1.10.2.min.js"></script>

<script>
    console.log($);
    console.log(jQuery);
</script>

I get a message that $ or jQuery is undefined: what’s wrong?

It’s just an empty index.html, with no other code.

Guja1501
  • 999
  • 7
  • 16
yeah its me
  • 1,131
  • 4
  • 18
  • 27
  • If you want a hosted version of jQuery you might want to use a [CDN version](http://stackoverflow.com/questions/6514072/is-it-bad-to-hotlink-jquery-from-jquery-com). – tadman Jan 21 '14 at 20:42
  • @tadman use googles url for it. – Shawn Jan 21 '14 at 20:43
  • 2
    @tadman That IS a CDN version. MaxCDN – Kevin B Jan 21 '14 at 20:43
  • @KevinB Right you are. I thought that was the download link pasted in there. – tadman Jan 21 '14 at 20:43
  • And, by using MaxCDN, it won't be blocked by companies (or countries) that block google-related traffic. – Kevin B Jan 21 '14 at 20:45
  • You also might want to search Stack Overflow for that error: [https://www.google.com/#q=%22%24%22+or+jQuery+is+undefined+site:stackoverflow.com](https://www.google.com/#q=%22%24%22+or+jQuery+is+undefined+site:stackoverflow.com). There's a few hits. (I don't feel the close reason was appropriate on your question given the breadth of answers to similar past problems. If you get closed again as a duplicate, then that is "shame on you"). – jww Jan 31 '14 at 18:02

3 Answers3

25

You used the href attribute to include the script to the file.

href is an invalid attribute for <script></script> tags. Use src instead...

<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
War10ck
  • 12,387
  • 7
  • 41
  • 54
5

You have an error in your declaration. You should use

<script src="...">

instead of

<script href="">.
alphabit
  • 454
  • 3
  • 8
-1
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

<script>
    console.log($);
    console.log(jQuery);
</script>

Always try to use js files on your local machine.

Umair Khan
  • 283
  • 3
  • 13