Multiple versions of jQuery for plugins

by Barney Carroll

HTML

<link rel="stylesheet" href="https://rawgithub.com/dimsemenov/Magnific-Popup/master/dist/magnific-popup.css">
<!--
Our markup, to test the plugins
-->
<p class="plugin1">
    Test plugin 1
</p>
<p class="plugin2">
    Test plugin 2
</p>
<!--
jQuery 1.9.1 
-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<!--
Plugin requiring jQuery 1.9.1
-->
<script>
    (function($){
        $('.plugin1').click(function(){
            if( $().jquery === '1.9.1' ){
                alert( 'Plugin 1 (requiring jQuery 1.9.1) works!' );
            }
        });
    }(jQuery));
</script>
<!--
jQuery 1.3.2 
-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<!--
Plugin requiring jQuery 1.3.2
-->
<script>
    (function($){
        $('.plugin2').click(function(){
            if( $().jquery === '1.3.2' ){
                alert( 'Plugin 2 (requiring jQuery 1.3.2) works!' );
            }
        });
    }(jQuery));
</script>
<!--
The reversion script
-->
<script>
    // Use `$` most of the time, except when invoking plugin2, when you'll need to use `$plugin2` to refer to jQuery.
    // So what would normally be expressed as `$('thing').doThis()` will need to be `$plugin2('thing').doThis()`
    $plugin2 = $.noConflict( true );
</script>