TypeError: n is not a function

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:

Read More
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.

enter image description here

enter image description here

Related posts

2 comments

  1. 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();
        });
    });
    
  2. //try below code (remove $ )

    jQuery(window).load(function() {
      console.log('Everything loaded');
      $('.slides').fadeIn();
    });
    

Comments are closed.