So, let's start with situation. I have a website which uses Jquery 1.4.2 as the main version of Jquery.
But user's are able to use custom templates which are using other versions(1.2.1,1.5.1,etc.). So it bring with it conflicts in some situations.
For example, here
//included in my main view
<script type="text/javascript" src="jquery-1.4.2.min.js" ></script>
<script type="text/javascript">
$(function () {
alert($().jquery);
});
</script>
//included in custom template
<script type='text/javascript' src='jquery-1.5.1.min.js'></script>
<script type="text/javascript">
$(function () {
alert($().jquery);
});
</script>
So both of them are alerting 1.5.1(because of initializing when document is ready). So I want to prevent this situations.
Now I've get only one solution in my head - use noConflict(true) and change all $ and Jquery symbols to new symbol in all plugins used in my site.
Is there more elegant solution or I really need to rename all plugin's used in my site?
P.S. Another way maybe will be using backwards compatibility plugins, but in this situation I will need to include a lot of plugins to make it compatible with all versions.
jQueryobject which is defined at that moment. So you just have to load them in the proper order. For using the correct version in your own code, thereadycallbacks get passed a reference to jQuery as first argument.(function($) {...}(jQuery)), i.e. inside the plugin$refers to whateverjQueryrefers to at that moment. In your case, otoh, you are accessing the global$, which is overwritten later by the second jQuery script. The equivalent in your case would be$(function($) {...}). Give it a try.