TypeError: $ is not a function when calling jQuery function

后端 未结 16 1846
慢半拍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条回答
  • 2020-11-22 03:08

    Double check your jQuery references. It is possible that you are either referencing it more than once or you are calling your function too early (before jQuery is defined). You can try as mentioned in my comments and put any jQuery reference at the top of your file (in the head) and see if that helps.

    If you use the encapsulation of jQuery it shouldn't help in this case. Please try it because I think it is prettier and more obvious, but if jQuery is not defined you will get the same errors.

    In the end... jQuery is not currently defined.

    0 讨论(0)
  • 2020-11-22 03:11

    You can avoid confliction like this

    var jq=jQuery.noConflict();
    jq(document).ready(function(){  
      alert("Hi this will not conflict now");
      jq('selector').show();
    });
    
    0 讨论(0)
  • 2020-11-22 03:11
    (function( $ ) {
      "use strict";
    
      $(function() {
    
        //Your code here
    
      });
    
    }(jQuery));
    
    0 讨论(0)
  • 2020-11-22 03:14

    Use

    jQuery(document).
    

    instead of

    $(document).
    

    or

    Within the function, $ points to jQuery as you would expect

    (function ($) {
       $(document).
    }(jQuery));
    
    0 讨论(0)
提交回复
热议问题