5

I've come across a fairly normal problem, but I can't solve it.
I tried to fix the jQuery scripts dozens of times, but it just won't work. It suddenly just stopped working after a few weeks.

I am positive that I included the jQuery script, and I did test if the site was alive.
However, it seems like my browser or server ain't loading it with the site load...

https://i.stack.imgur.com/g2R5G.png

It load my Google Analytics script perfectly fine, but it won't load the jQuery script. Even if I host i myself.

This is the code

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

<script type="text/javascript">
  $(document).ready(function(){
    $('img').hover(function(){
      $(this).data('jpg', $(this).attr('src'));
      $(this).attr('src',$(this).data('gif'));
    },
    function(){
      $(this).attr('src',$(this).data('jpg'));
    });
  });
</script>

Here, it produces the error on line #5 or line #15 in my website

https://i.stack.imgur.com/lPvtd.png

I am lost here, how do I fix this? It was working great, and then suddenly, boom, out of nothing, it stopped working. Have been trying to fix this, but I can't figure it out.

Cheers, thanks for reading

EDIT: Included a JSFiddle as it was requested in the comments. Hope I included the necessary code.

Sparky
  • 98,165
  • 25
  • 199
  • 285
Filuren
  • 661
  • 2
  • 7
  • 19
  • 1
    What's the obfuscated thing you have in the screenshots? Is it a streetview image? ;) – PeeHaa Mar 08 '12 at 23:07
  • Does it work if you move the ` – staticsan Mar 08 '12 at 23:09
  • Yeah double check it is in the head and also you can run that first line easier with jquery 1.7+ by: `$(function(){ /*do work on page load*/ });` ... that is when you get jQuery working :P – SpYk3HH Mar 08 '12 at 23:12
  • PeeHaa: No, it's just my website, I just blur the URL as it is not ready yet for launch. @staticsan: It is already in the tag. Should I try the tag? – Filuren Mar 08 '12 at 23:12
  • @SpYk3HH: The script code worked wonder a week ago or so, it just seems I have trouble loading the jQuery. Isn't the – Filuren Mar 08 '12 at 23:16
  • @ninjaboi21 "Isn't the – PeeHaa Mar 08 '12 at 23:17
  • 2
    Can you reproduce the problem in an environment we can actually look at? – Chuck Mar 08 '12 at 23:17
  • Like, for example, a JSFiddle? Because if I copy and paste the code you've given us there, it loads jQuery just fine. – Chuck Mar 08 '12 at 23:25
  • I hope this will do it: http://jsfiddle.net/YxGHM/3/ The idea is: when the mouse is not hovered, display the dog or JPG. When the mouse is hovered, display the dancing boy or GIF. This worked great, till a few days ago. EDIT: Not really sure about the `});//]]>` – Filuren Mar 08 '12 at 23:39
  • @ninjaboi21: Your jsfiddle works fine if you delete the ` –  Mar 08 '12 at 23:44
  • Made the JSFiddle work now, but I am still unable to load the jQuery script on my website. Anything I could test? – Filuren Mar 09 '12 at 00:20
  • Verify that it isn't the `$` reference by doing `console.log(window.jQuery)`. If that doesn't do it, then remove all other scripts including the analytics to see if that helps. If not, try a different CDN, like `http://code.jquery.com/jquery.min.js` –  Mar 09 '12 at 00:32
  • @am not i am: It just returns `undefined`, whether I use code.jquery.com or ajax.googleapis.com, it just doesn't load jQuery – Filuren Mar 09 '12 at 07:07

1 Answers1

3

Replace all "$" with "jQuery". If that works: jQuery.noConflict()

Shea
  • 1,965
  • 2
  • 18
  • 42