-1

I get this from console, Uncaught ReferenceError: $ is not defined(anonymous function) @ function.js:2 ..

this is my js code

$(function() {
    mobileNav();
});

function mobileNav() {
    $('.mobile-btn').on('click', function(){
        var status = $(this).hasClass('is-open');
        if(status){ $('.mobile-nav-toggle, .mobile-btn').removeClass('is-open'); }
        else { $('.mobile-nav-toggle, .mobile-btn').addClass('is-open'); }
    });

}

on local host everythings gone well, but on the server i got this js error..

<script src="/js/jquery-2.1.4.min.js" type="text/javascript"></script> <script src="/js/function.js" type="text/javascript"></script>

2 Answers2

2

$ is not defined error occur if your JQuery library is not loaded.

Please add the jquery library or if you have added the jquery library then check the path you have provided.

0

You have not added jquery in your code:

add this line if you want to use remote jquery CDN. I recommend to have a local copy on your server but if you want to use remote one i can suggest you the below one.

<script src = "https://code.jquery.com/jquery-2.1.4.min.js" ></script>

Edit

Also there might be an conflict with other jquery plugins if you are using jquery in your code, best way to do check it is by removing one by one plugin and see where it works.

Sourabh Kumar Sharma
  • 2,864
  • 3
  • 25
  • 33
  • I think its premature to to say he did not add the jquery. Its possible that there is just a conflict with another lib that uses the `$`. – guradio Oct 16 '15 at 05:15
  • Yup forgot to mention that. – Sourabh Kumar Sharma Oct 16 '15 at 05:16
  • Can you post your header scripts that you have included in your code in the question, may be you are included two different versions of jQuery which also causes this error, it will be good if you could post your code in the question – Sourabh Kumar Sharma Oct 17 '15 at 10:12