After all $(document).ready() have run, is there an event for that?
Dont know how to tell when the last $(document).ready()
function fired, but $(window).load()
function fires after the $(document).ready()
The safest thing to do is to invoke $(window).load()
inside $(document).ready()
. This will preserve execution order in all cases by making sure that your run-last code is not passed to $(window).load()
until all $(document).ready()
scripts have completed. Without this there are possible race conditions in some browsers where $(window).load()
may be invoked after all $(document).ready()
scripts have started but before all $(document).ready()
scripts have finished.
$(document).ready(function() {
$(window).load(function() {
// this code will run after all other $(document).ready() scripts
// have completely finished, AND all page elements are fully loaded.
});
});
Based on Ian's answer I figured this out (tested - working):
jQuery(document).ready(function() {
jQuery(document).ready(function() {
/* CODE HERE IS EXECUTED AS THE LAST .ready-CALLBACK */
});
});
Of course this is because the ready callbacks are invoked in the order they where assigned. At the moment, when your outer ready callback is invoked, all other scripts should have their ready callbacks already assigned. So assigning your ready callback (the inner one) now will lead to yours being the last one.
Try this neat trick/gross hack:
$(function(){
$(function(){
$("#my_slider").slider("value", 10);
});
});
Looks stupid right? It works because jQuery executes event handlers in the order they were added. Adding an event handler in your event handler is about as late as you can (just make sure you're not doing this on any of the sliders accidentally; it's very easy to do).
Proof of concept. http://jsfiddle.net/9HhnX/