JavaScript Uncaught ReferenceError: $ is not defined

                                                        

   On - 10 Feb, 2023
   By - Apu Gorai
The Uncaught ReferenceError: $ is not defined error occurs when the code is attempting to reference the jQuery library, but it has not been loaded yet.
This can occur if the jQuery library is not included in the HTML page, or if the library is included after the code that is attempting to access it.
To fix this issue, make sure to include the jQuery library in the HTML page before any other code that is attempting to use it.
Additionally, if the jQuery library is being loaded asynchronously, code that is dependent on it should be placed in the callback that is triggered when the library is loaded and ready.
If the jQuery library is being loaded from a CDN, it is also important to consider the possibility of the CDN being down or unresponsive.
An example of loading the jQuery library asynchronously using a callback is shown below. 
<script src="/jquery-3.6.1.min.js"
    onload="callbackFunc()"/>
<script>
    function callbackFunc() {
         alert('Hello World');
    }
</script>
The library can be loaded from a local copy or multiple CDN sources can be used in order to provide a backup if one of the sources is unavailable.
Load More »