Home > Development, WordPress > jQuery's no-conflict mode: yet another reason why it's the best

jQuery's no-conflict mode: yet another reason why it's the best

It took me a bit to find out why jQuery (now bundled with WordPress) was not working as I expected inside of the WP admin area. The script was being called, but my code like $("#foo") was not working. I really had no clue where to begin, since it still has all those old JS libraries/frameworks being called as well. It was due to Prototype being packaged with it and conflicting with the "$" shortcut.

Long story short, jQuery already planned for library conflicts and has a quick solution. The no-conflict mode allows you to define your own shortcut, and of course it works like a charm.

It's easy to do - just put this line in your code somewhere:

var J = jQuery.noConflict();

Now $("#foo") will be J("#foo") and it will not conflict with any other libraries that may be installed. I hope WP gets rid of all the other stuff and goes with pure jQuery and plugins soon enough though :)

Categories: Development, WordPress
  1. aiphes
    June 29th, 2011 at 08:19 | #1

    great solution is it global for all jquery's functions used by different plugin like fancybox,thickbox ..on a same website? i'm looking for that
    thanks

  2. Nebulas Website Design Essex
    July 12th, 2011 at 02:56 | #2

    Perfect thanks for the quick explaination. Don't know why other sites have to write long articles on how to do it, not got time to read all that just want a quick fix and this is it!

  3. Free Templates
    September 24th, 2011 at 22:38 | #3

    Thanks for this, but i still can't get my slider working correctly without conflicts.. soon as i enable any WP plugins my slider stops working.. any ideas ?

    Huge thanks in advance to anyone who can help with this

  4. mike
    September 26th, 2011 at 18:21 | #4

    I'd say find a jQuery-based slider that works with your version. That's the best I can say.

  5. Merk
    October 16th, 2011 at 09:13 | #5

    Great this is so simple.
    Thanks for sharing with us.

Comment pages
1 2 21
  1. July 29th, 2007 at 13:56 | #1
    Around the web | alexking.org
  2. August 21st, 2009 at 14:12 | #2
    Javascript libraries working together | Oikofugic Design
  3. April 21st, 2010 at 03:50 | #3
    jquery und mootools - TYPO3 Forum & Portal
  4. April 27th, 2010 at 01:26 | #4
    ??jQuery??????? | ????