Uncaught Referenceerror: $ is not defined at funcoes.js:2

Asked

Viewed 3,044 times

0

$('nav a').click(function(){
    e.preventDefault();
    var id = $(this).attr('href'),
        targetOffaset = $(id).offset().top,
        menuHeight = $('nav').innerHeight();

    $('html, body').animate({
        scrollTop: targetOffaset -59
    }, 500);
});

1 answer

0


This is because the dollar sign ($) is a alias (or shortcut) to jQuery. That’s why you need to add jQuery jQuery before calling funcoes.js. Ex:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="funcoes.js"></script>
  • Valdeir thanks for helping. But I’m already pulling both:<script src="funcoes.js"></script>&#xA;<script src="node_modules/jquery/dist/jquery.js"></script> Mais se jogo no console do googlechrome funciona o código. [! [insert image description here][1]][1] [1]: https://i.stack.Imgur.com/Afuid.jpg

  • 1

    @Carloshenrique , as I said in my reply. The jquery must come before functions.js. Put in your code exactly the way I did and testing.

  • Valdeir guy didn’t believe that was it, I touched now kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk Thank you very much man, vlw even, to laugh here for being that kkk

  • wmsouza, already solved,Thank you :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.