I have been doing some messing about with jQuery in SharePoint and I want to understand what is going on when there are multiple declarations of different versions on a page.
The way it seems to work is last one referenced wins. This is because the execution of the jQuery code sets window.jQuery = the current jQuery object.
I was wondering well what happens to the docReady function pointer stack, as that is surely contained within the version of jQuery that was executed.
Well truth is it’s complicated. The code you see below will execute 161 and 144 code and the events will occur in each ones own code block (closures), but then the values you get out of jQuery are that of the last one executed despite it being a closure, because the clousre version of $ you call in your first doc ready returns the window.jQuery object, not your closure so this code will always spit out 220.127.116.11.4 despite executing code from both code blocks. What does this mean, I haven’t got a clue, but I encourage you to debug this in firebug and see what code executes where, and if someone can explain to me why I see two function pointers in my 1.4.4 readyList code, that would be nice.
UPDATE:I’ve tried this recently and I dont know what crack I was smokin when I tried this, Im convinced I remember stepping thru two sets of jquery code, but then once inside the prior closure gets the new reference once inside, this is not the case when I just did it in VS2010. What is still interesting is that any plugins loaded after the first jquery reference are nuked on load of the second jQuery ref. HOWEVER the doc ready function pointer list is retained and both execute. I still stand by the next statement.
In conclusion I suppose I would say one version of jQuery would be nice on a page, if MS could kindly put something into sharepoint to manage it so we are all doing the same thing I’d appreciate that, and if the jQuery team could “just finish already” 😉
The Version is