1

I can't solve this problem where the console gives this error: Uncaught TypeError: $ is not a function. This is the code it points to:

<script type="text/javascript">
$(document).ready(function() {
    $(".linky").click(function(){
        var t = $(this); //<-ERROR POINTS HERE
        var y = $("#0"+t.attr("id")).offset().top;
        $('html,body').animate({scrollTop: y},500);
    });
});
</script>

Any help would be much appreciated!

Joshua Snider
  • 705
  • 1
  • 8
  • 34
FFlaser
  • 111
  • 1
  • 2
  • 8
  • 5
    Are you including jQuery library? If the answer is yes, is it loaded correctly (check console)? Is this code placed after jQuery loading line? – Claudio Redi Jun 03 '15 at 21:13
  • 2
    Whenever you get this error just check if you have included jquery library or not. Secondally it may be due to conflicts having more than one jquery libraries on the same page.. – Rohit Arora Jun 03 '15 at 21:13
  • FOR SURE YOU HAVE N'T INCLUDED JQUERY FILE – Nadeemmnn Mohd Jun 03 '15 at 21:18
  • If you are including the JQuery Library then you may want to post more of your code, like the HTML etc. – crazymatt Jun 03 '15 at 22:14
  • Is the jQuery script from a (re)source that is available? Open the console, do you have any loading resource error? like 404 or ... – Tiberiu C. Jun 04 '15 at 00:03

2 Answers2

7

Maybe jQuery.noConflict(); it's being used somewhere inside your site. Try with this:

<script type="text/javascript">
(function( $ ) {
  $(document).ready(function() {
    $(".linky").click(function(){
      var t = $(this); //<-ERROR POINTS HERE
      var y = $("#0"+t.attr("id")).offset().top;
      $('html,body').animate({scrollTop: y},500);
    });
  });
})(jQuery);
</script>
Topicus
  • 1,394
  • 1
  • 15
  • 27
0

You need to include the jquery script

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
Allen Tellez
  • 1,198
  • 1
  • 10
  • 14