$(document).ready() - $.isReady bug
Hi,
We have spent some time racking our heads why $(document).ready()
wasn't always firing and we finally found it.
The ready() function checks jQuery.isReady. If true, it fires straight
away, if false, it gets queued and fired once the document is ready.
This is fine if you have a page which registers a ready function on
the initial load of the page. At this point jQuery hooks itself up to
capture the documents ready event, fires your function and also sets
jQuery.isReady to true.
However, if you have a page with jQuery on it and don't register
anything on the first load, then jQuery.isReady is left to be false.
Then you load a script via ajax which calls $
(document).ready(functrion(){/*do stuff*/}) but it won't fire. Why?
because, the page is already loaded, so the document ready event
doesn't fire and hence doesn't set jQuery.isReady to true. Registering
a function at this point get's added to jQuery.readyList but it is
never run.
For now I have fixed this by appending this line to the end of the
jQuery file which registers a dummy function.
//////////////////////////
$(document).ready(function(){});
//////////////////////////
This function does nothing other than make sure jQuery hooked up the
ready event in the case that no ready function was externally queued
on jQuery.readyList on the initial page load. There may be a better
fix for this by a jQuery guru, buth this does the trick for now.
Giulio