简体   繁体   中英

Plugins with different jQuery versions

In current implementation there is old version of jquery (1.7.x) and old plugin depends on this version of jquery.

And now I want to add new jQuery plugin which require latest jquery verson, but can not remove the old version of jquery as there will be lots of changes.

Can we use different jquery versoin for new plugin without conflict?

I am trying following solution, but does not work.

<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
$(document).ready(function () {
$("#element").flexModal();
});
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>  
<script type="text/javascript">
 var jQuery_1_8 = $.noConflict(true);
 jQuery_1_8(document).ready(function () {
 jQuery_1_8("#element2").flexModalLatest();
});
</script> 

Plugins names are just for this code demo.

Alternatively you can use new jQuery (1.11 and up) with an official jQuery migrate plugin to support deprecated/removed functions.

http://jquery.com/download/#jquery-migrate-plugin

try this :

<!-- load jQuery 1.7.2 -->
<script type="text/javascript" src="http://example.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
var jQuery_1_7_2 = $.noConflict(true);
</script>

<!-- load jQuery 1.8.3 -->
<script type="text/javascript" src="http://example.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
var jQuery_1.8.3 = $.noConflict(true);
</script>

instead of

 $('#selector')....;

you'd do

jQuery_1_7_2('#selector')....; 

or

jQuery_1_8_3('#selector')....;

https://api.jquery.com/jQuery.noConflict/

After reading the docs, I think you're using it back-to-front - after loading the second jquery version, use var jQuery_1.7.2 = $.noConflict() to get reference to the original older version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM