I am creating a web widget to be posted on other websites. In the widget it will call jQuery and I dont want the jQuery to conflict with other JavaScript libraries that the website may have installed. When I load the jQuery I would like to call jQuery like this:
JQuery_MYSite('id').find('selector');
I found out if I do this then $ will not be able to be used even if the other website uses $.
When the widget loads it find out if jQuery is loaded. If so, then it will use the $ to call jQuery. But I know $ is not unique to just jQuery – other javascript libraries use it. So how can I use my own jQuery prefix with without interfering with the website owners prefix.
I don’t think you can achieve this, because
jQuery.noConflict()must be called after the other scripts have been loaded. So, if there is no way for you to know about the other scripts, then you won’t have a way to avoid the conflicting.Wrap your widget code with an auto-executing anonymous function: