What jQuery event is fired right after $ (document) .ready ()?

I have a lot of HTML generated on $(document).ready() . I have a simple window system. But not only is it generated on $(document).ready() - also some HTML elements (different JS files put stuff in $(document).ready() ). I want my window system to be generated after calling $(document).ready() . So, how do I handle the function that will be called after the completion of all the code registered in $(document).ready() ?

+4
source share
6 answers

There is another event that will be released later. it $ (window) .load (); This starts after loading all resources.

But maybe you need this:

 function loadWindowSystem(){ // load window system here } $(document).ready(function(){ // do some html stuff here loadWindowSystem(); }) 

This way you can separate your code from functions.

+6
source
  $(window).load(function(){ //some code after ready }); 
+6
source

I usually do not recommend 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 }); 
+3
source

If you want something to work right after all the calls to $(document).ready() , you can place it once anywhere on your page:

 $(document).ready(function() { setTimeout(function() { // call your code here that you want to run after all $(document).ready() calls have run }, 1); }); 

This will trigger a call along with all other document.ready calls, but it sets a short timeout that will be executed after all other document.ready calls have completed.

+2
source

nothing happens after this function, so if you have some ajax loaders, just think that you can do this to wait for them all and then start rendering

EDIT But I wonder why you just don't structure your code to eliminate this.

0
source

$(document).ready() is called immediately after the DOM has finished loading. pageLoad() is called next in timer 0, but be careful, it starts after every partial postback.

Edit: added side note - this will be taken into account only when using ASP.NET, the mentioned pageLoad functionality is separated from jQuery. Read more here

0
source

Source: https://habr.com/ru/post/1391637/


All Articles