18
Aug
2009
WordPress & jQuery: “$ is not a function”
If you are trying to add your own jQuery code to WordPress, and have had the error “$ is not a function” show up on Firebug, here is the fix:
Convert all dollar signs ($) to ‘jQuery’
The dollar sign is reserved in WordPress for the Prototype library, which is why it errors out. For example, instead of:
$().ready(function() {
$("#select_me").show();
});
Change it to:
jQuery().ready(function() {
jQuery("#select_me").show();
});




Add one more name to the list of people whose days you’ve saved with this article. Thank you!
Thank yOU!
What about this case? Do I change the code that’s between the php tags as well, or only $(document) into jQuery(document)…
$(document).ready(function() {
// ro map init
javascriptMap.init({
‘mapUrl’: ”,
‘xmlUrl’: ”,
‘mapElm’: ‘#xmlMap’,
‘mapWidth’ : , // map width
‘mapHeight’ : , // map height
‘mapMargin’: ”
});
});
Yes, the only thing you need to change is:
$(document)
to
jQuery(document)
Thank you – got to love google search and people like yourself who care to post their fixes. Saved me a lot of time!
Thank You!!!!!
This is more of theoretical question, but now that jQuery has won the javascript framework wars (based on popularity), why is it that we still reserved the “$” sign for Prototype? Sure, I used to use that framework myself, back in the day, but I haven’t touched Prototype in years, and I haven’t personally observed any WordPress plugins using Prototype. What do you think about just re-enabling the dollar sign in WordPress for jQuery?
You bring up an interesting point that I fully agree with. Why do we have to find a workaround on something that 99% of users use in the first place? Maybe a stubborn WordPress team member is part of the other 1%…
Would this not work as well, to use the $ within the function($)?
In that way, if you have a lot of other functions within your jQuery() it would save a bit of typing:
jQuery().ready(function($) {
$(“#select_me”).show();
$(“#select_me”).etc();
$(“#select_me”).etc();
});
YOU ARE A LIFE SAVER…thanks!
[...] http://elementdesignllc.com/2009/08/wordpress-jquery-is-not-a-function/comment-page-2/#comment-2439 [...]
Thanks–worked!
Made my day. Thank you!
Damn’, you are my hero.
Who would have thought that solving this bloody error was so easy. Just doing a search and replace….
Juergen
jQuery(‘#leftsidebar,#page,#sidebar’).equalizeCols();
still it is showing same error like jQuery(“#leftsidebar”, “#page”, “#sidebar”).equalizeCols is not a function
goli, the issue is most likely with “equalizeCols”. Make sure you are spelling that correctly, and that the equalizeCols script is being loaded properly after jQuery is loaded in the header of your website.
Why did I decide not to trust in a Google search sooner? Thank you, Chad. This saved the day. I’ve been going back and forth with a plugin developer trying to figure out where the conflict was and this was the trick.
I freaking LOVE YOU!!!! I was pulling my hair out on this one!
Thanks a ton. I had been trying to get around this for a couple or hours.
You just saved me like 3 hours of futzing around with code that was never broken. Thanks!
it also works in Magento phtml files if you put in some jQuery and have problems with the “is not a function” stuff.
What if the $ sign is inside a library e.g: jquery.prettyGallery.js ? I can’t change all $ -> jQuery. There should be other easy solutions????
If you don’t wish to change all $ into jQuery one by one this is another solution. by wraping all $ inside a (function($){ … })(jQuery)
example:
function($) {
// we can now rely on $ within the safety of our “bodyguard” function
$(document).ready( function() {
alert(”hurrrrray! now we can use $ easily!”);
} );
} ) ( jQuery );
Thank you! Was completely stuck on that one.
my appreciation! thanks for ur help.
You save my life dude, thanks for the tip, I was so in the blind. lol crazy Prototype, glad it solved.
Amazing. Couldn’t work out what was going on and this saved my sanity.
Thanks
Thanks Alot !!! you saved my day
thanks for the article. That worked for me
I have the same problem when integrating a mail-chimp form. Changing $ to jQuery fixed it. Thanks!
Do I need to change the “$” to “jQuery” in every script?
For example i’m using jscrollpane plugin.
Do I need to change all the dollar signs in jScrollPane.js too?
Thank you on beforehand!
You’re a live saver
Works perfectly. Thanks a bunch.
I’m glad I’ve found this page, you saved me a lot of time.
Thanks a lot.
Thanks, This came in handy after a WP upgrade (oddly my 2.x stuff was find with the $)
Help!
I have changed $ to jQuery , but it still does not work.
Please help me. thanks so much.
What error message are you now receiving?
I you were here in Chile, I would invite you a cup of red wine. Thanks! it works fine.
Great and consise!!!!
It works as a solution of the jquery problem in magento. It is more detailed too.
thank you!!!
Thanks! Stupid prototype! X(
You are the Don.
You made my day
Great!
Thank you!
THANKS!!!!! just what i needed after hours of searching