Here is the trick I'm using. On the main page, announce
var postReadyEvents = [];
Then, on the child pages, when you have some code to be executed last, execute
postReadyEvents.push(function() {
Now, in the main page of $ (document) .ready (), do
for(var i = 0; i < postReadyEvents.length; i++) { postReadyEvents[i](); }
When you have $ (document) .ready () on both the child pages and the main pages, the child page starts first and the main page starts last. This approach gives you the ability to control when a specific block of code is executed.
source share