Answer: 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.
jQuery is a lightweight, "write less, do more", JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.
Basically $ is an alias of jQuery() so when you try to call/access it before declaring the function, it will endup throwing this $ is not defined error . This usually indicates that jQuery is not loaded and JavaScript does not recognize the $. Even with $(document).
jQuery needs to be the first script you import. The first script on your page
<script type="text/javascript" src="/test/wp-content/themes/child/script/jquery.jcarousel.min.js"></script>
appears to be a jQuery plugin, which is likely generating an error since jQuery hasn't been loaded on the page yet.
you need to put it after wp_head(); Because that loads your jQuery and you need to load jQuery first and then your js
In my case, the error occurred because I was using the wrong version of jquery.
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
I changed it to:
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
set this jquery min js
script src="http://code.jquery.com/jquery-1.10.1.min.js"
in wp-admin/admin-header.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With