jQuery: How do I stop the page being displayed until it's been processed?

Posted by Alistair Christie on Stack Overflow See other posts from Stack Overflow or by Alistair Christie
Published on 2010-03-28T09:13:51Z Indexed on 2010/03/28 9:23 UTC
Read the original article Hit count: 284

Filed under:

I'm using jQuery to modify the style of some pages in a large set of existing Web pages. This works, but the problem I have is that, for longer pages, the page is briefly visible with the wrong styles before the javascript kicks in and transforms the page.

I'm using this kind of thing (the alerts are just to emphasize the problem):

$(document).ready(function(){
   ...
   alert("at this point the page is visible unstyled");
   $('body').addClass('myStyle');
   alert("now page looks like I want it to");
   ...
}

How do I prevent the browser from displaying the page until $(document).ready(function() completes?

© Stack Overflow or respective owner

Related posts about jQuery