2

I am new in JQuery. Help me I got Error Microsoft JScript runtime Error:'$'is Undefined

See more

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="Scripts/jquery.min.js"></script>
<script type="text/javascript">        
    $(window).scroll(function () {
        var startValue = 70; // scrollTop value when to start incrementing
        var stopValue = 300; // scrollTop value when to stop incrementing
        var scrollTop = $(window).scrollTop();
        if (scrollTop > startValue && scrollTop <= stopValue)
            $("#pct").text((((scrollTop - startValue) / (stopValue - startValue)) * 100).toFixed(0));
        else if (scrollTop <= startValue)
            $("#pct").text(0);
        else if (scrollTop >= stopValue)
            $("#pct").text(100);
    });
</script>
 <style type="text/css">
     body {
        height:2000px;
      }

     #pct {
         height:150px;
         width:150px;
         background-color:#369;
         font:bold 60px verdana;
         padding:20px;
         position:absolute;
         top:400px;
         left:200px;
    }
  </style>
  </head>
 <body>
 <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> 
 <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
 <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
 hi
 <div id="pct">0</div>
</body>
</html>

See jsFiddle It works in jsFiddle but not in IE is somthing missing help me? Thanks

Community
  • 1
  • 1
YKJ
  • 149
  • 6

3 Answers3

2

You're most likely missing the line:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • i download it and then use it locally but still getting same error – YKJ Jul 21 '13 at 07:40
  • @YKJ Do you have the script included via the above line, in the `` of your document, before your script above? Simply having it in the folder isn't enough. – Daedalus Jul 21 '13 at 07:49
  • I wish I could upload image so that what Explain it nicely. Sorry this is giving popup showing above error – YKJ Jul 21 '13 at 07:49
  • 1
    Please edit your question and add the head of the document, showing how you load jquery. – Barmar Jul 21 '13 at 07:51
  • I added my page have a look on it. – YKJ Jul 21 '13 at 08:05
  • It looks correct, assuming the path is right. Like I said above, are there any error messages in the Javascript console, complaining that it can't load jquery.min.js? – Barmar Jul 21 '13 at 08:09
  • 1
    Can you give us the URL to the page – Barmar Jul 21 '13 at 08:09
  • Sorry I unable to create URL because i am doing it locally – YKJ Jul 21 '13 at 09:03
  • 1
    Sorry, it's impossible for us to tell what's wrong then. Everything you need to know should be in the Javascript console. – Barmar Jul 21 '13 at 09:05
0

use latest jquery file

http://jsfiddle.net/nbSNA/12/

$(window).scroll(function() {
    var scrollTop = $(window).scrollTop();
    if (scrollTop > 70 && scrollTop <= 300)
        $("#pct").text((((scrollTop-70)/(300-70))*100).toFixed(0));
    else if (scrollTop <= 70)
        $("#pct").text(0);
    else if (scrollTop >= 300)
        $("#pct").text(100);
});
Hushme
  • 3,108
  • 1
  • 20
  • 26
  • That won't work. The argument passed to an event handler is the event, not the jQuery function. – Barmar Jul 21 '13 at 07:24
  • I use this but i think something is missing. is there any thing needed to initialize? – YKJ Jul 21 '13 at 07:24
0

Make sure you include the jquery library before you make calls to it, even if the calls are in other scripts, references to them should appears after the jquery include.

ifell
  • 61
  • 1