Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

javascript - TypeError: jQuery(...).ready(...) is not a function

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 it).

jQuery(document).ready(function(){
    jQuery('.comtrig').on('click',function(){
        $(this).next().animate({'display':'inline'},1000);
    });
})();

I get the error TypeError: jQuery(...).ready(...) is not a function in FF or Uncaught TypeError: object is not a function in Chrome.

  • Solution 1 was to replace $ with jQuery but I obviously already did that as shown above
  • I'm not in Wordpress either
  • I'm using only jQuery and the above mini script, no other JS
  • jQuery itself seems to load fine enter image description here

What am I missing here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...