jQuery : Error: $(document).ready is not a function
July 25, 2009 5:50 am6 Comments
Yes it bloody is! Quite often when I’m mucking about with WordPress firebug will throw the following error:
jQuery : Error: $(document).ready is not a functionIf you see this error it’s because another framework is in conflict with jQuery – most usually in my case it’s mootools or scriptaculous, anyway here’s the work-around. The people who developed jQuery had the foresight to include a function which makes jQuery play nicely with other frameworks which all use the $ sign as a staple part of their code. Introducing the jQuery.noConflict(); function.
The jQuery.noConflict(); command you can replace the $ sign with the word jQuery throughout your code.So, for example, instead of using the normal dom ready function: $(document).ready(function() you would use: jQuery(document).ready(function() just don’t forget to call the .noConflict function before this, so the whole shebang would look like this:
<script src=”mootools.js”></script> // this is the conflicting framework <script src=”jquery.min.js”></script> // this is your jQuery <script> jQuery.noConflict(); // start substituting $ for jQuery jQuery(document).ready(function(){ jQuery.yourjQueryfunctions(); }); </script>instead of:
<script src=”mootools.js”></script> <script src=”jquery.min.js”></script> <script> $(document).ready(function(){ $.yourjQueryfunctions(); }); </script>
- <script src=“prototype.js”></script>
- <script src=“jquery.js”></script>
- <script>
- jQuery.noConflict();
- jQuery(document).ready(function(){
- jQuery(‘div’).stuff();
- //notice, that the $sign has been replaced with the word jQuery
- });
- // And you can use Prototype with $(…)
- $(‘id’).hide();
- </script>
Categorised in: Web Development
This post was written by WillyNilly
6 Comments
Bloody hell! Finally! Thanks so much for the fix. Its taken me ages to fix this… 🙂
Hi
Thanks so much for the fix.
Cheers man…it works.
Yeah Really great.. It works well.. Thanks so much
Thanks mate, just helped me out of a spot.
Great fix…Thank you…