jQuery.noConflict()
is only for using two different versions of jQuery or loading two different libraries using $
. Good example is:
<script src="jquery-1.9.1.js"></script>
<script>
jq = jQuery.noConflict();
</script>
<script src="jquery-1.11.3.js"></script>
<script>
console.log(jq.fn.jquery); // 1.9.1
console.log($.fn.jquery); // 1.11.3
console.log(jQuery.fn.jquery); // 1.11.3
</script>
The usecase I was talking is, some plugins require older versions, say, 1.9.1
and a few require the newer versions. In that case, you can use the noConflict
to load the old ones and new ones in the same page.
See the better use-case here:
<script src="jquery-1.9.1.js"></script>
<script src="old-plugin.js"></script>
<script>
$(".old-plugin-holder").oldPlugin();
jq = jQuery.noConflict();
</script>
<script src="jquery-1.11.3.js"></script>
<script src="new-plugin.js"></script>
<script>
console.log(jq.fn.jquery); // 1.9.1
console.log($.fn.jquery); // 1.11.3
console.log(jQuery.fn.jquery); // 1.11.3
// Initialization
jq(".old-plugin-holder").oldPlugin(); // Runs using jQuery 1.9.1
$(".new-plugin-holder").newPlugin(); // Runs using jQuery 1.11.3
</script>