Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 889
RubenGeert Avatar asked Feb 13 '14 13:02

RubenGeert


People also ask

Is not a function $( document .ready function ()?

ready is not a function" error occurs for multiple reasons: Placing second set of parenthesis after the call to the ready() method. Loading the jQuery library after running your JavaScript code. Forgetting to load the jQuery library.

What does $( document .ready function () do?

$( document ). ready()A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ). ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.

What is $( document .ready () and $( window .load () in jQuery?

ready() and $(window). load() event is that the code included inside onload function will run once the entire page(images, iframes, stylesheets,etc) are loaded whereas the $(document). ready() event fires before all images,iframes etc. are loaded, but after the whole DOM itself is ready.

Is not a function Typeerror is not a function?

This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.


1 Answers

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.

like image 128
Jai Avatar answered Sep 20 '22 06:09

Jai