I want to disable some specific “feature” that one my plugins does to the DOM when the DOM is ready.
If I put my code inside the onload callback, will it always get executed after the ready callback?
I want to be sure in 100% that even if there aren’t any images of just few the ready will be executed before the onload.
While I think @jAndy’s answer is right, you can afford yourself some extra assurance by also placing the code in the
onloadwithin aready()call.Just make sure that your main
ready()call comes first.So if the
ready()has already fired by the time theonloadfires, youronloadcode will still run. (An internal flag is set once the DOM is ready, so future.ready()calls are immediately invoked.)If the
.ready()has somehow not fired when theonloadhappens, that will mean that your originalready()code is first in the internal Array, and the new.ready()code will be added to the end of the Array.EDIT:
Looking at the source for the main
jQuery.readyhandler that is fired when the DOM is ready (which in turn, fires the list of the user’s.ready()handlers), it appears as though there’s an IE bug where the handler fires a little early.To remedy this bug, jQuery makes the handler asynchronously invoked until it can actually see
document.body.It would seem that because of this asynchronous looping of the handler, then IE would at least be possibly prone to having the
window.onloadhandler invoked before the.ready()handlers.Adding to the
.ready()handler list within theonloadas I described above should remedy this.