Avoiding conflicts when using jQuery and EPiServer Composer

Posted on October 25, 2010 by Frederik Vig in EPiServer

On a customers site today I had some JavaScript errors when using Composer on page edit. After firing up Firebug to inspect the errors I saw that Composer is using Prototype, which is another popular JavaScript library, that also uses the ‘$’ for its wrapper function.

To avoid this conflict I used a popular design pattern, that passes a self executing anonymous function to the jQuery namespace with the jQuery object.

// Your jQuery code is safe here

This fixed the errors. Definitely goning to add this to all my jQuery code from now on :).

I recommend checking out How Good C# Habits can Encourage Bad JavaScript Habits: Part 1, the whole series is fantastic and teached me quite a few things that I’ll take with me.

Related Posts: