The jQuery Uncaught ReferenceError: $ is not defined error is one of the most common and frustrating issues developers encounter when working with jQuery. It usually appears in the browser console when JavaScript tries to use the jQuery object or its shorthand alias $, but the browser cannot find it. In simple terms, the code is asking for jQuery, but jQuery has not been loaded, has not been initialized correctly, or is not available in the current scope. Understanding this error is essential for anyone building interactive websites, debugging frontend code, or maintaining older web applications that still rely heavily on jQuery That's the part that actually makes a difference..
Introduction: What the jQuery Uncaught ReferenceError Means
When you see a message like Uncaught ReferenceError: $ is not defined, it means JavaScript is trying to access a variable named $, but that variable does not exist in the current execution context. Also, in most cases, $ is the shorthand alias for jQuery. Normally, when jQuery loads successfully, it creates a global object called jQuery and also assigns $ as a shortcut to that same object.
To give you an idea, this code works only if jQuery has already been loaded:
$(document).ready(function () {
$("button").click(function () {
alert("Button clicked!");
});
});
If jQuery is missing, delayed, blocked, or loaded in the wrong order, the browser will throw the jQuery uncaught referenceerror is not defined message. The same issue may also appear as Uncaught ReferenceError: jQuery is not defined, depending on whether the code uses $ or jQuery directly Turns out it matters..
This error is not random. It almost always points to a loading, ordering, scope, or configuration problem. The good news is that it is usually easy to diagnose once you know what to check Took long enough..
Common Causes of jQuery Uncaught ReferenceError Is Not Defined
1. jQuery Is Not Loaded at All
The most obvious cause is that the jQuery library was never included in the page. If your HTML does not contain a <script> tag that loads jQuery, then $ will not exist Easy to understand, harder to ignore..
As an example, this code will fail if jQuery is not loaded:
$("#menu").hide();
To fix this, you need to include jQuery before any script that uses it:
If you are using a CDN, the concept is the same, but the source will be a hosted URL instead of a local file No workaround needed..
2. jQuery Loads After Your Custom Script
Even if jQuery is included, it may load too late. JavaScript executes in the order it appears. If your custom script runs before jQuery has finished loading, the browser will not recognize $ Worth keeping that in mind..
Incorrect order:
Correct order:
This is one of the most frequent reasons for the jQuery uncaught referenceerror is not defined error. Always load jQuery first, then load plugins and custom scripts that depend on it.
3. Incorrect File Path
If the browser cannot find the jQuery file, it will not load the library. So this often happens when the path in the <script src="... "> tag is wrong Worth knowing..
For example:
If the file is actually located in a folder named assets instead of js, the browser will fail to load it. You can confirm this by opening the browser developer tools and checking the Network tab. If the jQuery request returns a 404 Not Found status, the path is incorrect.
4. CDN or External Resource Is Blocked
If you load jQuery from a CDN, the request may fail because of network restrictions, firewall rules, ad blockers, or an offline environment. In that case, the browser cannot download jQuery, and $ remains undefined.
To test this, open the page in another browser or disable extensions temporarily. If the error disappears, the issue may be related to a blocked external resource Most people skip this — try not to..
5. jQuery Is Loaded With `async
ordefer` Attributes
The async and defer attributes change when a script executes relative to HTML parsing. When you add async to the jQuery tag, the browser downloads it in parallel but executes it as soon as it finishes, which may be after your inline scripts have already run The details matter here..
Here, main.js can execute before jQuery is ready, leaving $ undefined. The safest fix is to remove async from the jQuery tag, or to ensure your dependent scripts also wait for jQuery to be available.
6. Your Script Runs Before the DOM Is Ready
Even with jQuery loaded correctly, your code may run before the elements it targets exist. If you call $("#menu").hide() before the #menu element has been parsed, the selector returns nothing. While this does not throw the $ is not defined error directly, it is often confused with it when combined with poor load ordering Still holds up..
Wrap your code in a document-ready handler so it runs only after the DOM is fully built:
$(document).ready(function () {
$("#menu").hide();
});
Or use the shorter form:
$(function () {
$("#menu").hide();
});
7. A Conflicting Library Overrode $
Many libraries use $ as a shorthand. If you load another library such as Prototype or MooTools alongside jQuery, that library may claim $ first. When jQuery runs in this situation, it can either overwrite the other library or, if jQuery is missing, leave $ pointing to something that is not jQuery But it adds up..
If you need to coexist with another library, use jQuery's noConflict mode and refer to jQuery by its full name:
jQuery.noConflict();
jQuery("#menu").hide();
Or pass $ into a local scope:
jQuery(document).ready(function ($) {
$("#menu").hide();
});
8. jQuery Is Loaded Inside a Module or Bundler Scope
When you use modern tooling such as Webpack, Vite, or native ES modules, $ may not be available globally. Importing jQuery inside a module does not automatically attach it to the global window object, so inline scripts or other files that expect a global $ will fail.
Import jQuery explicitly in each module that needs it:
import $ from "jquery";
$("#menu").hide();
If you must expose it globally, assign it to window yourself:
import $ from "jquery";
window.$ = $;
window.jQuery = $;
How to Diagnose the Error Quickly
When you encounter the jQuery uncaught referenceerror is not defined message, work through these checks in order:
- Open the browser console and confirm the exact error and the line where it occurs.
- Check the Network tab to verify jQuery loaded with a
200 OKstatus, not404. - Confirm the
<script>order: jQuery must appear before any script that uses it. - Remove
asyncordeferfrom the jQuery tag if you rely on it being ready immediately. - Look for other libraries that may be overriding
$. - If you use a bundler or modules, make sure jQuery is imported where it is used.
Most cases are resolved by the first three checks. A correct path, a proper load order, and a successful network request eliminate the majority of these errors Small thing, real impact..
Conclusion
The $ is not defined error is one of the most common issues in jQuery development, but it is also one of the most predictable. In almost every case, the root cause is that jQuery is either not loaded, loaded too late, loaded from a broken path, or blocked by the environment. Secondary causes such as conflicting libraries, module scoping, and the async attribute round out the list.
Short version: it depends. Long version — keep reading.
Strip it back and you get this: that jQuery must be available before any code tries to use it. Load it first, verify the file path resolves correctly, and confirm the request succeeds in the Network tab. Plus, once jQuery is reliably in place, wrap your logic in a document-ready handler and, in modern build setups, import it explicitly where you need it. Following these practices will prevent the error from appearing and make your pages far more dependable Small thing, real impact..