#3185 closed bug (duplicate)
ready() doesn't work correctly for scripts loaded dynamically
Reported by: | natrius | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.3 |
Component: | event | Version: | 1.2.6 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
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.
You can just set
Right after you load jQuery.