I have lots of HTML generated on $(document).ready()
. I have a simple window system. But not only it is generated on $(document).ready()
- also som
By adding another handler function ones the document is ready, the handler will almost certainly be last one in the ready event queue. Effectively giving you an instant "post" ready handler function.
$(document).ready(function() {
$(document).ready(function() {
// code to run "after" ready
});
});
$(document).ready
When multiple functions are added via successive calls to this method, they run when the DOM is ready in the order in which they are added.
Note that this will only work as long as no ones else uses this "trick".
I usually don't advocate using setTimeout
, but you can build on top of @jfriend00's answer to create a more abstract approach:
$(document).ready(function() {
setTimeout(function() {
$(document).trigger('afterready');
}, 1);
});
$(document).bind('afterready', function() {
// call your code here that you want to run after all $(document).ready() calls have run
});
there is nothing after this function , so if you have some ajax loaders, only think you can do is to wait for all of them and then start rendering
EDIT But i wonder why you dont just structuralize your code to eliminate this.
$(document).ready()
is called just after the DOM has finished loading.
pageLoad()
is called next on a 0 timer, but beware it is run after every partial postback.
Edit: Added side note - this will only count if using ASP.NET, the pageLoad functionality mentioned is separate from jQuery. See more info Here
There is another event which is fired later. it's $(window).load(); This is fired after all resources are loaded.
But perhaps you want this:
function loadWindowSystem(){
// load window system here
}
$(document).ready(function(){
// do some html stuff here
loadWindowSystem();
})
This way you can separate your code in functions.
You can use
$(window).on('load', function () {
alert("Window Loaded");
});
$(window).load(function(){
alert("Window Loaded");
}
has been removed from jQuery.