TypeError: jQuery(…).ready(…) is not a function

前端 未结 5 1611
忘了有多久
忘了有多久 2021-01-17 07:36

OK, I know this has been asked before but none of the answers seems to apply to my case. I\'m trying to get a very tiny piece of jQuery running (I\'m just getting started on

相关标签:
5条回答
  • 2021-01-17 07:55

    These Errors:

        TypeError: jQuery(...).ready(...) is not a function
        or
        Uncaught TypeError: object is not a function
    

    are also happens if you implement Jquery library after your code, it should be before, ORDER MATTER here.

     <script src="@Url.Content("~/Scripts/jquery-1.10.2.js")"></script>
    
    0 讨论(0)
  • 2021-01-17 08:03

    There are two issues in the code.

    1 - The brackets at the end of the code.

    2 - $(this) should have been jQuery(this) or $ inside function.

    jQuery(document).ready(function($){
        $('.comtrig').on('click',function(){
            $(this).next().animate({'display':'inline'},1000);
        });
    });
    
    0 讨论(0)
  • 2021-01-17 08:12

    Remove the extra brackets () at the end. Keep the code as below.

    jQuery(document).ready(function(){
        jQuery('.comtrig').on('click',function(){
            $(this).next().animate({'display':'inline'},1000);
        });
    }); // <== remove () from here
    
    0 讨论(0)
  • 2021-01-17 08:12

    Passing jquery object this way works for me.

    $(document).ready(function () {
        console.log("jquery");
    }(jQuery));
    
    0 讨论(0)
  • 2021-01-17 08:17

    try to remove this (); at the end of doc ready:

    jQuery(document).ready(function(){
      jQuery('.comtrig').on('click',function(){
        $(this).next().animate({'display':'inline'},1000);
      });
    }); //<----remove the (); from here
    

    (); is normally used to have a Immediately-Invoked Function Expression (IIFE) which has some kind of syntax like this:

    (function(){
       // your stuff here
    })(); //<----this invokes the function immediately.
    

    Your errors:

    in firefox = TypeError: jQuery(...).ready(...) is not a function

    in chrome = Uncaught TypeError: object is not a function

    because:

    Your document ready handler is not a Self-executing anonymous function.

    0 讨论(0)
提交回复
热议问题