• # June 20, 2008 at 9:58 pm

    Hi all,
    I’ve been building a site with wordpress and came across a bit of a problem trying to insert a jquery script to the header.
    Apparently it doesn’t like the $ and won’t recognise any function with the $ before it! I was adding this between some script tags.

    < ------ stuff here -----/>

    No luck! After a lot of head scratching i found an article that recommended this instead.

    jQuery(document).ready(function($) {
    < ------ stuff here -----/>

    Works like a charm. You can now use the $ inside the document.ready function. It’s to do with other javascript librarys used in WordPress so they don’t conflict. I’d never heard of this so i hope it’s useful to someone else!

    Tob :D

    # June 21, 2008 at 2:28 pm

    This reply has been reported for inappropriate content.

    Very nice tip, thanks! I’ve been thinking about including some jQuery stuff on the site here and this will very likely come up.

    Usually jQuery plays very nicely with other libraries and even has some built in functions for helping with that. The "$" is just shorthand for "jQuery" so just using that everywhere (even within the function) can help with cross-compatibility as well.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.