Unfortunately you're always going to get this flash of unstyled content whenever you do this kind of class setting with javascript since the JS is loaded after everything else on the page.
Without knowing what specifically you need to achieve, some suggestions would be to use some kind of placeholder CSS on the offending elements (setting a width / height / colour / whatever it is you need) to try to mitigate the effect. You can also try to mitigate it by making sure your page is optimised as much as you possibly can, so give it a run through with yslow and see if there are any speed improvements you can make.
The only other (and best) way would be to use klew's suggestion and insert the class server-side instead of waiting until the DOM has loaded for JS to do its stuff.