jQuery: "TypeError: $ is not a function" when calling function
Quote from HeelpBook on February 27, 2018, 5:30 pmI have a simple jQuery script in a WordPress plugin that is using a jQuery wrapper like this:
$(document).ready(function(){
// jQuery code is in here
});I am calling this script from within my web portale and I'm loading it AFTER the jQuery framework has loaded.
When I check the page in debug console I constantly keep receiving the error message:
TypeError: $ is not a function
$(document).ready(function(){How to fix it?
I have a simple jQuery script in a WordPress plugin that is using a jQuery wrapper like this:
$(document).ready(function(){ // jQuery code is in here }); |
I am calling this script from within my web portale and I'm loading it AFTER the jQuery framework has loaded.
When I check the page in debug console I constantly keep receiving the error message:
TypeError: $ is not a function $(document).ready(function(){ |
How to fix it?
Quote from HeelpBook on February 27, 2018, 5:36 pmA quick fix to this issue is to embed the function into another "dummy" function:
(function($){
// jQuery code is in here...
})(jQuery);This issue is often due to the noConflict(): the jQuery library included in most web solution could be set to the noConflict() mode. This is to prevent compatibility problems with other JavaScript libraries that WordPress can link.
In the noConflict() mode, the global $ shortcut for jQuery is not available.
A quick fix to this issue is to embed the function into another "dummy" function:
(function($){ // jQuery code is in here... })(jQuery); |
This issue is often due to the noConflict(): the jQuery library included in most web solution could be set to the noConflict() mode. This is to prevent compatibility problems with other JavaScript libraries that WordPress can link.
In the noConflict() mode, the global $ shortcut for jQuery is not available.