× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Adding jQuery messing things up?

Dominic Myers
Mar 29, 2015
<p>I've recently helped a customer who was trying to do something in a legacy application that was coded with the <a href="http://prototypejs.org/">prototype</a> JavaScript language. Once-upon-a-time <a href="https://jquery.com/">jQuery</a> and Prototypes were the VHS and Betamax of JavaScript libraries and, like VHS, jQuery won that particular battle and without resorting to courting dodgy film producers. Anyway, I'm old enough to remember his pain and remembered that the writers of jQuery were kind enough to realise that someone might have both libraries - so they created the <a href="https://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/"><code>noConflict()</code></a> directive which allowed developers to let existing libraries use the $ shortcut while renaming jQuery's $ shortcut.</p> <p>It's dead easy to use. Simply drop this into your script tag:</p> <pre><strong>var</strong> $j <span style="color:#808030">=</span> jQuery<span style="color:#808030">.</span>noConflict<span style="color:#808030">(</span><span style="color:#808030">)</span><span style="color:#800080">;</span> </pre> <p>Then, whenever you need to call a jQuery function, simple replace the <code>$</code> with <code>$j</code>.</p> <p>Needless to say you can replace <code>$j</code> with anything just so long as you set it in your script. I seem to remember mine being <code>jQuery</code> rather than <code>$j</code>...</p>
comments powered by Disqus