-3

I have the following line of code in my head:

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

I have the following lines of code at the beginning of my body:

<script>
    $(function () {
        alert("JQUERY!");
    });
</script>

My JavaScript Console gives the following error:

Uncaught ReferenceError: $ is not defined

I am using Google Chrome.

I have read all of the answers at JQuery - $ is not defined, but as far as I can tell, I am obeying everything there. I have confirmed that the link in the first script is valid.

I would expect jQuery to load, but it is failing to do so (silently). What is the correct syntax to make jQuery load from the CDN?

Community
  • 1
  • 1
Evorlor
  • 7,263
  • 17
  • 70
  • 141
  • It is relevant. Load jQuery *once*. The second instance stomps on the first. Use the most recent version unless it causes problems. – isherwood Mar 03 '15 at 17:44
  • @danronmoon It does. The first script is in my header. The second script is in my body. – Evorlor Mar 03 '15 at 17:45
  • Well you can not have code using jQuery BEFORE you include jQuery. It is like trying to eat a pizza before you make it. – epascarello Mar 03 '15 at 17:46
  • @epascarello I don't The first script is in my header. The second script is in my body. – Evorlor Mar 03 '15 at 17:46
  • 2
    wait, you have two different jQuery versions? yikes. You should not have two versions. – epascarello Mar 03 '15 at 17:48
  • why are you including jQuery twice? head and body load on the same page. Remove the one in your footer. – Jacob Raccuia Mar 03 '15 at 17:48
  • I removed the one from the footer. Same result. – Evorlor Mar 03 '15 at 17:49
  • Got a live link we can look at? – j08691 Mar 03 '15 at 17:51
  • What browser are you using? jQuery 2x isn't compatible with older versions of IE. – Howard Renollet Mar 03 '15 at 17:51
  • One thing I'd recommend (other than removing the second version of jQuery, unless you need it) is updating the `src` of your first script. Remove the 'http' protocol `` - Handles both secure/non-secure sites. – Jack Mar 03 '15 at 17:51
  • 1
    You're going to have to come up with an example that demonstrates the problem you're having. It's very unclear what scripts you have and what the order of them is. – JJJ Mar 03 '15 at 17:51
  • OK...I am going to make a file demonstrating problem and then post the entire file. Assuming this question does not get closed before then. – Evorlor Mar 03 '15 at 17:53
  • Figured it out. No clue why it was how it was...so I asked. http://stackoverflow.com/questions/28839143/why-do-comments-affect-the-logic-of-my-file – Evorlor Mar 03 '15 at 18:23

1 Answers1

3

The Script element should not be a self closing tag.

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

to

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
epascarello
  • 204,599
  • 20
  • 195
  • 236
  • 1
    Still same error :-/ – Evorlor Mar 03 '15 at 17:53
  • This indeed was one of my issues. The other issue was weird comments :-/ http://stackoverflow.com/questions/28839143/why-do-comments-affect-the-logic-of-my-file Thanks for your help!! – Evorlor Mar 03 '15 at 18:23