Friday, December 26, 2014

Is it possible to handle conflicts between 2 versions of jQuery loaded in the same page?

Question: Is it possible to handle conflicts between 2 versions of jQuery loaded in the same page?

Answer:  Using jQuery.noConflict, you can make multiple versions of jQuery coexist on the same page.
<!-- load jQuery 1.1.3 -->
<script type="text/javascript" src="http://example.com/jquery-1.1.3.js"></script>
<script type="text/javascript">
var jQuery_1_1_3 = $.noConflict(true);
</script>

<!-- load jQuery 1.3.2 -->
<script type="text/javascript" src="http://example.com/jquery-1.3.2.js"></script>
<script type="text/javascript">
var jQuery_1_3_2 = $.noConflict(true);
</script>
Then, instead of $('#selector').function();, you'd do jQuery_1_3_2('#selector').function(); or jQuery_1_1_3('#selector').function();.

No comments:

Post a Comment