jQuery: How do I stop the page being displayed until it's been processed?
- by Alistair Christie
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?