I'm building a Wordpress site that has the following bit of JS:
jQuery(window).load(function($) {
console.log('Everything loaded');
$('.slides').fadeIn();
});
I'm seeing "Everything loaded" in the console, but the following line causes an error:
Uncaught TypeError: n is not a function
I don't understand what's causing the problem. The JS file has jQuery as a dependency, and there are other jQuery functions that are working fine. It's just the above section that's causing an error.
Here's a screenshot from the console, because some people are having difficulty believing the above code is causing the error.
The issue is because you have set the event parameter as provided to the handler function with the name of $
. This overwrites the jQuery instance of $
, hence the error. You just need to remove the $
from the function parameters:
jQuery(window).load(function() { // < remove the $ here
console.log('Everything loaded');
jQuery('.slides').fadeIn();
});
Note that from your comments you're looking to alias the jQuery
variable as a $
after using noConflict()
. To do this you can use this signature document.ready
handler:
jQuery(function($) {
$(window).load(function() {
console.log('Everything loaded');
$('.slides').fadeIn();
});
});
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