Use jQuery With Other Libraries Like Prototype and MooTools

Hello Friends, There are so many javascripts libraries available in web world like jQuery, prototype, moo tools which having so many functionality and so many features available to make site attractive. But sometime when we need to use two or more libraries together to achieve some functionality, they conflicts with each other. So to avoid conflict with each other we have to override variable used in library with other variable name. Below is then explanation of how to use jQuery With Other Libraries Like Prototype.

Define jQuery

<script language=”javascript” src=”js/jquery.js”></script>


// After Defining jquery file you must asign a new variable to jQuery here i have used it as “phpzone”
// The reason to use this is “$” is used in both the js Jquery and Prototype and its conflicting one another.
// Prototype uses$ for id based selection
// jQuery $ uses CSS based selection
// so here “$” would be replaced with “phpzone”
// so the conflict with prototype $ will be removed.

<script type=”text/javascript”>
var phpzone = jQuery.noConflict();
</script>

// Define prototype js

<script language=”javascript” src=”js/prototype/prototype.js”></script>

=====================================
In Normal use of jQuery syntax will be
=====================================

<script type=”text/javascript”>
$(document).ready(function()
{
// Your code;
}
</script>

=====================================
In jQuery+Prototype together syntax will be
=====================================

<script type=”text/javascript”>
hoot(document).ready(function()
{
//YOur Code
}
</script>

———————————————–

Enjoy Programming.

  • Hi,

    Do you know how to use jQuery in a greasemonkey script used for a page containing prototype already?

  • Hi,

    Do you know how to use jQuery in a greasemonkey script used for a page containing prototype already?

Subscribe to PHP Freelancer

Enter your email address: