Ticket #3185 (closed bug: duplicate)
ready() doesn't work correctly for scripts loaded dynamically
|Reported by:||natrius||Owned by:|
Consider a page that does not call ready(). If ready() is called by a script that is dynamically loaded on such a page after it has already been loaded, the function passed to ready() will never be called (in Firefox 3). DOMContentLoaded is apparently not fired for elements inserted after the original page load, and since the listener for that event isn't attached until the first call to ready(), jQuery never calls the function. My current workaround is to include a dummy call to ready() in all of my pages where this problem manifests itself so jQuery will catch DOMContentLoaded for the initial page load, and the function I'm passing to ready() from the dynamically loaded HTML will just fire immediately. (This might make you wonder why I bother using ready() at all. It's complicated.)
Although my use case is rather strange, this still seems like undesirable behavior.