
JavaScript Uncaught ReferenceError: $ is not defined
Today we’re going to talk about how to solve the problem - JavaScript Uncaught ReferenceError: $ is not defined.
This error occurs when you try to use jQuery and haven't included the jQuery CDN link in your HTML page.
The $ sign is an alias (shorthand) of jQuery, so this error means that either you have not included the jQuery library in your code or jQuery is not loaded.
See the following example - how the error occurs. We have not included the jQuery CDN link in our code.
<button>Click Me</button> <script> $(document).ready(function() { $("button").click(function() { alert('Yes'); }); }); </script>
Fixing this problem is not very difficult! All you need to do is make sure you include the jQuery (library) CDN link on every web page where it is needed (Search for jQuery CDN in your favorite search engine).
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script> <button>Click Me</button> <script> $(document).ready(function() { $("button").click(function() { alert('Yes'); }); }); </script>
Once you include the jQuery library on your webpage, refresh your browser and everything should be working as expected!