How to avoid conflict between two version of Jquery library?

Jeetu Verma picture Jeetu Verma · Mar 19, 2013 · Viewed 14.5k times · Source

In jsp page, i am using struts2-jquery-plugin-3.2.1.jar (it uses internally jquery-1.6.4.js) and i am using facebox (it uses jquery-1.4.3.min.js). So my struts2-jquery-plugin-3.2.1.jar load first then facebox jquery. but when i put jquery-1.4.3.min.js my struts2-jquery-plugin-3.2.1.jar stops working and when i remove jquery-1.4.3.min.js obviously my facebox stops working. I follow these forum : here and here but not able to fix this problem.One guy advise me to use new version of struts2-jquery-plugin, but i can't use because if i use new version of struts2-jquery-plugin then some code of my project stopped working. Please share your knowledge on this problem.

Answer

Alexander Gor picture Alexander Gor · Mar 19, 2013

you need to use jQueryNoConflict feature: http://api.jquery.com/jQuery.noConflict/

so your library needs to be defined like:

<script src='jquery-1.3.2.js'></script>
<script>
var jq132 = jQuery.noConflict();
</script>

<script src='jquery-1.4.2.js'></script>
<script>
var jq142 = jQuery.noConflict();
</script>

and then you can use both of them like this:

jq132.ajax(....);
jq142('#my-elem').hide();