7

$(document).ready() executes the code when all HTML elements have been loaded.

How to execute jQuery code after all of the CSS rules have been applied?

I have few stylesheets linked to the page and it takes some time to load the page. Element layout changes during the time of the loading.

For usability purposes I need to correct the element layout after all of them have target sizes. Otherwise I get wrong sizes of those elements.

Now I do it on focus or after some timeout, but need this after the page loads.

2
  • $(document).ready() This line means the jQuery should only start executing once your entire page is loaded. There may be an issue with the CSS. Commented Dec 14, 2010 at 16:22
  • window.load should do , it will till all the images loads also Commented Dec 14, 2010 at 16:23

2 Answers 2

11

$(window).load() fires after the whole page (images, CSS, etc.) has loaded.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I was playing with $(document).load(), but I just needed $(window).load()
@Emmett How would I get this to work if I am dynamically injecting CSS? thanks
2
$(window).load(function() {

 // executes when complete page is fully loaded, including all frames, objects and images

 alert("window is loaded");

});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.