Uncaught TypeError: undefined is not a function (anonymous function) in Wordpress
javascript, jquery, wordpress
Solution
Wordpress is running in noConflict mode by default, change the DOM ready wrapping to
jQuery(function($){
// your code goes here
});
otherwise $ will be undefined
Da Codex
Problem
I am getting the following error, which appears to be Javascript not interpreting the $ symbol. Uncaught TypeError: undefined is not a function main.js:1 (anonymous function) main.js:1 Appended below is the main.js code. This was working fine sometime back. I am trying to find out pointers to where to look for the issues, i.e. theme, jquery imports, etc. Any suggestions are welcome. ``` $(function(){ var cardHeight = 0; function _setCardHeight(){ $(".subpage-box").each( function(){ var current_height = $(this).height(); cardHeight = ( current_height > cardHeight) ? current_height : cardHeight; }); $(".subpage-box").each( function(){ if( $(this).height() < cardHeight ){ $(this).height( cardHeight ); } }); } function _setNavStyle(){ $("menu-main-menu > li > a").each( function(){ var text = $(this).html(); if( $(this).contains("for") ){ } }); } _setNavStyle(); _setCardHeight(); }); ```