Delaying a jquery script until everything else has loaded

chrism picture chrism · Jun 18, 2009 · Viewed 206.4k times · Source

I have a jquery script which I need to run only once everything else on the page, including some other javascripts (over which I have no control) have finished doing their thing.

I though perhaps there was an alternative to $(document).ready but I haven't been able to find it.

Answer

Jose Basilio picture Jose Basilio · Jun 18, 2009

You can have $(document).ready() multiple times in a page. The code gets run in the sequence in which it appears.

You can use the $(window).load() event for your code since this happens after the page is fully loaded and all the code in the various $(document).ready() handlers have finished running.

$(window).load(function(){
  //your code here
});