Javascript does not work :(

Asked

Viewed 2,228 times

-4

Good morning.

I linked the javascript on my site as follows:

script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">

and one of the codes is this, inserted just after the body, to fix menu after scrolling:

    <script type="text/javascript">
            jQuery("document").ready(function($){

            var nav = $('.menu');

            $(window).scroll(function () {
                if ($(this).scrollTop() > 10) {
                    nav.addClass("fixar");
                } else {
                    nav.removeClass("fixar");
                }
            });
    </script>

But nothing works, I’ve tried the "hello world" to test the js but neither does it work. Anyone has any idea what might be working?

  • 1

    missing you close tags.. at the end of everything do not close the initial function.. adds another "});"

  • 2

    Please enter the full Code of your page.

  • "inserted just after the body" - And why don’t you put it within of <body>? Or better yet, inside the <head>?

  • sir_ask really was it. Thank you very much :)

  • 2

    This feels really wrong jQuery("document").ready(function($){, you should probably use jQuery(document).ready or jQuery.ready

1 answer

1

Friend the structure should be as it is:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Teste</title>
  </head>
  <body>

  </body>
  <script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
  // AGORA QUE O JQUERY FOI IMPORTADO, VOCÊ PODE COMEÇAR A ESCREVER SEUS CÓDIGOS QUE UTILIZAM A BIBLIOTECA.
 <script>
   $(function() {
    console.log( "ready!" );
   });
 </script>
</html>

Don’t forget to consider separating Html from Javascript to improve readability.

Browser other questions tagged

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