Web Tools Table Maker3schools TranslateImage CompressorFavicon Icon GeneratorCrop & Resize Image
Apu
Apu February 04, 2023 › #HowTo #Javascript

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).

The most common cause of the "Uncaught ReferenceError: $ is not defined" error is executing jQuery code before the jQuery library file is loaded. So make sure you execute the jQuery code only after the jQuery library file has finished loading.
<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!

save
listen
AI Answer
Write Your Answer
loading
back
View All