How to Fix Uncaught ReferenceError: $ is not defined in jQuery
Answer: Execute Code after jQuery Library has Loaded
The most common reason behind the error "Uncaught ReferenceError: $ is not defined" is executing the jQuery code before the jQuery library file has loaded. Therefore make sure that you're executing the jQuery code only after jQuery library file has finished loading.
Also if you're including the jQuery library file dynamically, inspect the page source using the browser's developer tool to ensure that it is included correctly and at right place.
Let's take a look at the following example to understand how it basically works:
ExampleTry this code »
<title>jQuery - $ is not defined</title>
alert("jQuery is working perfectly.");
<button type="button">Test jQuery Code</button>
If you're still getting this error there might be some other reasons, for example, if you have a local copy of the jQuery library file it might be edited or corrupted. Download a fresh copy the jQuery library file from the official website or use CDN link as we've used in the above example.
Here are some more FAQ related to this topic: