-1

Ok, so I wrote this in my script:

$(document).ready(function(){ alert("works"); })

just a normal document.ready check and it throws 7 errors at me

Errors screenshot

Can you help me guys?

3 Answers3

0

From the error, it seems that you are including the jQuery library after you are calling $(document).ready.

Include your jQuery before any other script in the <head>

Z-Bone
  • 1,534
  • 1
  • 10
  • 14
  • That's it! Thank you :D I just followed the tutorial, didn't know that you should include jquery above every other script – Szymon Kądziołka Mar 19 '17 at 23:26
  • Note that you should include JavaScript at the end of the body tag for better loading, not in the head. See my answer for an SO link about why this is the best practice. – John Vandivier Mar 19 '17 at 23:28
  • @JohnVandivier I agree, but my point was he needed to include jQuery before the scripts that called `$`. Otherwise `$` would always be undefined.. For simplicity matters I wanted to outline the problem this way, in case his code was in the beginning of the body and so on.. – Z-Bone Mar 19 '17 at 23:36
  • @SzymonKądziołka Im glad I could help, in case you found this helpful be sure to upvote.. Thanks – Z-Bone Mar 19 '17 at 23:37
  • I can just accept your answer, can't upvote because i don't have enough rep, anyway thank you guys both! – Szymon Kądziołka Mar 19 '17 at 23:50
0

Did you include JQuery library? Look at this example:

$(document).ready(function(){
    alert("works");
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Marco Salerno
  • 5,131
  • 2
  • 12
  • 32
0

Your code is ordinary jQuery and should work if there are no library conflicts.

Did you import jQuery? If so check whatever else you imported and ensure there is no conflict. You can try using jQuery.noConflict() to get around any conflicts with other libs.

I'd also suggest you load your JavaScript at the end of the body tag to improve page loading, not in the head as others have suggested. jQuery does need to be included before any dependent code is run of course.

Community
  • 1
  • 1
John Vandivier
  • 2,158
  • 1
  • 17
  • 23