TypeError: $ is not a function when calling jQuery function

后端 未结 16 1816
慢半拍i
慢半拍i 2020-11-22 02:42

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

}         


        
16条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 02:49

    By default when you enqueue jQuery in Wordpress you must use jQuery, and $ is not used (this is for compatibility with other libraries).

    Your solution of wrapping it in function will work fine, or you can load jQuery some other way (but that's probably not a good idea in Wordpress).

    If you must use document.ready, you can actually pass $ into the function call:

    jQuery(function ($) { ...
    

提交回复
热议问题