1

Is there a way to use AddClass in jQuery to add a class while a page and the assets are loading?

For example you could add a class of loading to the body tag.

You can't use the DOM ready function can you?

3
  • 3
    why not just give it the class in your html and then use .removeClass when the document is done loading? Commented Jul 23, 2012 at 17:28
  • That's a good idea. So just add a class of loading and then using the DOM ready function to remove the class? Commented Jul 23, 2012 at 17:30
  • yeah, either the document ready event or window load event, depending on your needs. Commented Jul 23, 2012 at 17:33

2 Answers 2

3

Putting my comment as an answer so this question can be marked as answered...

Set the loading class in the html and then use .removeClass to remove it once the document has finished loading.

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

Comments

0

This may give you some ideas of how to go about doing this.

https://plus.google.com/116910304844117268718/posts/UkaymyuTzaF

What I usually do is setup a attribute and then have JS turn it off when all the assets are ready. In CSS then I define a loading animation on areas of the body where I want them to appear.

Comments