Home > Enterprise >  WordPress page: Uncaught TypeError: $ is not a function
WordPress page: Uncaught TypeError: $ is not a function

Time:10-07

I'm getting this error with the code below embedded in a WordPress page. I can't find what is wrong with it.

<script>
  jQuery(window).load(function($) {
    if ($(".default-hero .hero-image img").length) {
      console.log($(".default-hero .hero-image img").css("height"));
      // Hero image exits. Adjust the .default-hero .inside .row to the minimum height of the image.
      $(".default-hero .inside .row").css("min-height", $(".default-hero .hero-image img").css("height"));
    }
  });
</script>

CodePudding user response:

load does not return a reference to jQuery like ready() does. It is the event object which is not a function.

(function($){
  jQuery(window).load(function() {
    console.log($);
  });
})(jQuery);
  • Related