-4

My code editor is throwing errors when I save this js file because of errors like:

-'$' was used before it was defined.

-Expected exactly one space between 'function and '('

This is what's in my JS file:

$(document).ready(function() {
$(window).scroll(function() {
    if ($(window).scrollTop() > 970) {
       $('.navbar').addClass('navbar-fixed-top');
    }
   });
});

I am using HTML, CSS, and JS. I am trying to use the JQuery library but it is not being recognized by my html file. I am inserting it above my external .js file, so I don't think that is the issue. Here is what is in my HTML file:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="js/tether.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/main.js"></script>

I am using the brackets editor, where the error is being thrown

Anyone know what the issue might be? Thanks in advance.

flarow432
  • 45
  • 1
  • 5
  • 3
    `Expected exactly one space between 'fucntion and '('` looks like you spelled `function` wrong – Charlie Fish Dec 22 '17 at 20:20
  • 1
    Sounds like you have a very strict linter enabled on your text editor. What text editor are you using? Try looking into the settings to disable or understand your linter. – Goose Dec 22 '17 at 20:20
  • @CharlieFish sorry I actually typed the errors out, the editor has it right. Will edit to reflect the correct spelling. – flarow432 Dec 22 '17 at 20:24
  • 1
    change `http://ajax` to `https://ajax` – Mohamed-Yousef Dec 22 '17 at 20:25
  • So these are "error messages" - they indicate where you have got something wrong. You need to fix them. – James Gaunt Dec 22 '17 at 20:28
  • @Mohamed-Yousef tried it and it is still throwing errors – flarow432 Dec 22 '17 at 20:31
  • what lines are the errors referring to? – Liora Haydont Dec 22 '17 at 20:32
  • @LioraHaydont There are two sections to the errors (JS Lint and ES Lint): An example of one of the errors in the JS Lint is : '$' was used before it was defined $(document).ready(function(){ An example of one of the rrors in the ES Lint is: ERROR: '$' is not defined [no-undef] $(document).ready(function(){ – flarow432 Dec 22 '17 at 20:35
  • You can try something like that: jQuery(document).ready(function($) { $(window).scroll(function() { if ($(window).scrollTop() > 970) { $('.navbar').addClass('navbar-fixed-top'); } }); }); – Hanif Dec 22 '17 at 20:36
  • Have you tried what’s suggested in the answers to [this question](https://stackoverflow.com/questions/18251388/jquery-and-jslint-was-used-before-it-was-defined)? – agrm Dec 22 '17 at 22:25
  • @flarow432 did u tried the answer i suggested? –  Jan 01 '18 at 02:58
  • Yes, but it did not work. I got it to work another way, it was a bootstrap issue, thanks for your help! – flarow432 Jan 10 '18 at 18:25

1 Answers1

0

Below works fine for me.

<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script>
    $(document).ready(function() {
      window.alert("Hello Jquery is Working....."); //put whatever you want to do here
    });
  </script>
</head>
<body>
   
</body>
</html>
William-H-M
  • 1,050
  • 1
  • 13
  • 19