Use other javascript library with jQuery using jQuery.noConflict

We all know that many javascript libraries like Prototype, MooTools etc. use  $ as a function or variable name and jQuery uses the same.

But in the jQuery $ is just the alias name for “jQuery” and hence we can get all the functionality without the use of $. There by it facilitates us to use other library along with it.

So for this we will override jQuery’s default $ name by calling jQuery.noConflict()

If you are including other library file first then jQuery file then call the function before other library gets used.

Sample format:

<script src="prototype.js"></script>

<script src="jquery-1.4.2.min.js"></script>

<script  type="text/javascript">

jQuery.noConflict();

// Use jQuery via jQuery(...)

jQuery(document).ready(function(){

jQuery("#id1").hide();

});

// Use Prototype with $(...)

$("#id2").hide();

</script>

Or

If you are including jQuery file first then other library file then we need not to override $ function using jQuery.noConflict(). Simply

<script src=" jquery-1.4.2.min.js"></script>

<script src="prototype.js"></script>

<script  type="text/javascript">

// Use jQuery via jQuery(...)

jQuery(document).ready(function(){

jQuery("#id1").hide();

});

// Use Prototype with $(...)

$("#id2").hide();

</script>
Be Sociable, Share!
You can leave a response, or trackback from your own site.

Leave a Reply

CommentLuv badge
 

Powered by WordPress