Why Won’t my jQuery Play Nice with WordPress?

Code in question here: http://pastebin.com/PN29WKNq

It worked on the HTML page I tested it on. Its supposed to add “display: none” to the content divs and then add “display: block” when the appropriate tab is clicked. But it just changes to “display: none” and never changes.

Related posts

Leave a Reply

2 comments

  1. WordPress automatically loads jQuery in “no conflict” mode so that it will be compatible with other libraries. This means the $ variable isn’t used for jQuery within WordPress.

    Rewrite your code to use the full jQuery keyword when you begin your closure like this:

    jQuery(document).ready(function($) {
    
        // ... other code in here
    
    });
    

    This is functionally the same as $(document).ready(function() { but uses the full name of the jQuery object to avoid noConflict issues. By passing jQuery in to the closure as the $ variable you can then use $ like normal inside the closure.