Weblog of Nazly Ahmed

Nazly Ahmed

Nazly Ahmed

Web Developer. PHP Addict. Wordpress Hacker. FOSS Enthusiast. (Micro)Blogger. Photo Hobbyist. Cricket Fanatic. Husband. Dad.

All these years I have been only using jQuery as a Java Script framework. But I came across this situation where I had to use both jQuery and Prototype in one of my projects. This unavoidable situation resulted in jQuery functions not working as its supposed to. The obvious reason was a conflict between the two libraries. A Google search revealed that this is a common problem and the good news was jQuery already had a solution for it.

“Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery’s case, $ is just an alias for jQuery, so all functionality is available without using $. If we need to use another JavaScript library alongside jQuery, we can return control of $ back to the other library with a call to $.noConflict():”

<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
  // Code that uses other library's $ can follow here.

It’s simple as that. It’s simply why the rest of the world and I love jQuery..!!
More info can be found here

Posted on 3rd February 2011 12:34:15