[Solved] uncaught referenceerror: $ is not defined jquery/javascript error

Previous

In this post, we will see how to resolve uncaught referenceerror: $ is not defined jquery error.

In jQuery, $ represents jQuery function. You will get this error when you are trying to access anything before loading jQuery.

For example:
request //uncaught referenceerror: $ request is not defined
var request
request // works fine

There can be multiple reasons for this issue.Let’s understand them one by one.


1. You did not add jQuery script

You did not add jQuery script to your PHP/JSP/ASP file correctly. You can use directly link it to jQuery or GoogleCDN or MicrosoftCDN to use jQuery script.

You can also download jQuery script and reference it locally for faster performance.


2. You are using jQuery tag before jQuery is loaded.

It could be that you have your script tag called before the jquery script is called.

For example:

It will result in $ is not defined.
Change the sequence and it should work fine.

So dependent script should be included after jQuery.
Let’s see another example
Let’s say jquery.plugin.js is declared before jquery.min.js, so jquery.plugin uses $, it will complain that $ is not defined which is logical as jQuery was not loaded at correct place.


3. Incorrect path/Typo/old jquery location

You might have put an incorrect path, or there may be type in your file.

For example:
You have misspelt in script as type=”text/javacsript”. If you notice that here, there is a typo in javascript spelling, and it can cause this issue.

Another reason may be that you are referring to an old jQuery hosted location, which is no longer maintained or moved to a different location.


4. You are offline

This seems bizarre but this may be also the reason for this error.You are working offline but trying to load jQuery from internet.
You can simply download the jQuery.js and use it locally rather then downloading from internet.

That’s all about how to fix uncaught referenceerror: $ is not defined jquery/javascript error.

Previous

Add Comment