Using jQuery with other Javascript Libraries: jQuery.noConflict CodeUnit 02 JAN 2010

You’ll often find yourself using frameworks that may be running a number of different javascript libraries such as MooTools, jQuery and ProtoType (depending on the various involved developers’ plugin preferences of course), which leaves you with the interesting quandry of what to do with the shared $ variable that most libraries tend to have a different use for.

Thankfully though, jQuery comes bundled with a nifty little function to deal with this hassle for us.

jQuery.noConflict() is a function that when run, gives control of the $ variable back to whichever library first implemented it. Of course, once run you do need to change your approach to calling jQuery magic by using the jQuery variable, for example where you might have in the past used $(‘div p’) as a selector, you would now have to replace it with jQuery(‘div p’).

The jQuery.noConflict function must be called after including the main jQuery javascript file but before including any other conflicting library, as well as before any other conflicting library does actually get used. Interestingly enough though, you can actually make the function call right at the end of the main jQuery.js file itself, to globally disable the $() jQuery alias across the site.

Useful eh?

Related Link:

Related Posts:

About Craig Lotter

South African software architect and developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.

  • Odewumi babarinde

    I am so very grateful for this hint, av been battling with this challenge since, just to find out that i had to put the jQuery.noConflict() before the conflicting library. Thanks a lot and GOD Bless you

  • No problem, glad I could be of assistance! :)