I have a project where my code will have to coexist with code in web pages designed elsewhere. My code will use jQuery, and so there may be an issue if the parent page already runs jQuery (and maybe jQuery plugins).

I would have thought the correct thing to do would be to add my jQuery version at the closing <body> tag (so it loads last) and then do:

var myJQ=jQuery.noConflict(true);

That way I hand back '$' and 'jQuery' to the page's own jQuery code and plugins so that they use the version of jQuery for which they were designed. But the jQuery docs warn that using 'true' may prevent other plugins working. I would like to understand that - but I'm afraid I don't get it! Surely it's the other way round? If I simply do "noConflict()", then pre-existing code using the jQuery variable will be using a different version than planned for, and that might cause problems? Whereas "noConflict(true)" would protect against that?

I have a project where my code will have to coexist with code in web pages designed elsewhere. My code will use jQuery, and so there may be an issue if the parent page already runs jQuery (and maybe jQuery plugins). I would have thought the correct thing to do would be to add my jQuery version at the closing <body> tag (so it loads last) and then do: var myJQ=jQuery.noConflict(true); That way I hand back '$' and 'jQuery' to the page's own jQuery code and plugins so that they use the version of jQuery for which they were designed. But the jQuery docs warn that using 'true' may prevent other plugins working. I would like to understand that - but I'm afraid I don't get it! Surely it's the other way round? If I simply do "noConflict()", then pre-existing code using the jQuery variable will be using a different version than planned for, and that might cause problems? Whereas "noConflict(true)" would protect against that?

I have a project where my code will have to coexist with code in web pages designed elsewhere. My code will use jQuery, and so there may be an issue if the parent page already runs jQuery (and maybe jQuery plugins). I would have thought the correct thing to do would be to add my jQuery version at the closing <body> tag (so it loads last) and then do: var myJQ=jQuery.noConflict(true); That way I hand back '$' and 'jQuery' to the page's own jQuery code and plugins so that they use the version of jQuery for which they were designed. But the jQuery docs warn that using 'true' may prevent other plugins working. I would like to understand that - but I'm afraid I don't get it! Surely it's the other way round? If I simply do "noConflict()", then pre-existing code using the jQuery variable will be using a different version than planned for, and that might cause problems? Whereas "noConflict(true)" would protect against that?

I have a project where my code will have to coexist with code in web pages designed elsewhere. My code will use jQuery, and so there may be an issue if the parent page already runs jQuery (and maybe jQuery plugins). I would have thought the correct thing to do would be to add my jQuery version at the closing <body> tag (so it loads last) and then do: var myJQ=jQuery.noConflict(true); That way I hand back '$' and 'jQuery' to the page's own jQuery code and plugins so that they use the version of jQuery for which they were designed. But the jQuery docs warn that using 'true' may prevent other plugins working. I would like to understand that - but I'm afraid I don't get it! Surely it's the other way round? If I simply do "noConflict()", then pre-existing code using the jQuery variable will be using a different version than planned for, and that might cause problems? Whereas "noConflict(true)" would protect against that?

I have a project where my code will have to coexist with code in web pages designed elsewhere. My code will use jQuery, and so there may be an issue if the parent page already runs jQuery (and maybe jQuery plugins). I would have thought the correct thing to do would be to add my jQuery version at the closing <body> tag (so it loads last) and then do: var myJQ=jQuery.noConflict(true); That way I hand back '$' and 'jQuery' to the page's own jQuery code and plugins so that they use the version of jQuery for which they were designed. But the jQuery docs warn that using 'true' may prevent other plugins working. I would like to understand that - but I'm afraid I don't get it! Surely it's the other way round? If I simply do "noConflict()", then pre-existing code using the jQuery variable will be using a different version than planned for, and that might cause problems? Whereas "noConflict(true)" would protect against that?

I didnt even know "noConflict" used parameters.

I usually declare:

var $j = jQuery.noConflict(); 

Then use "$j".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.