How to Fix Uncaught ReferenceError: $ is not defined in jQuery
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
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:
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.
need an explanation for this answer? contact us directly to get an explanation for this answer