To avoid this issue, I’d suggest inserting the following code directly after opening your page’s
<script>document.documentElement.className += " js";</script>
js class to the document’s root node (in most cases, the
Update: Tim Huegdon mentioned, rightly, that
class isn’t actually a valid attribute on the
html element, and that it might be better to set the
js class on the document’s
body element instead. It’s a valid point, one which ought not be ignored out of hand. I’m sticking with
document.documentElement for a simple reason: I know it works stably in every browser I’ve tested (IE6+, FF2+, Safari 2+, Opera 9.5+). I’ve heard anecdotal evidence of problems in IE caused by manipulating the document’s
body while it’s loading (“Operation Aborted”, and the like), which I’ve never experienced with this technique, and which I’d like to avoid.
Update to the Update: Martijn van der Ven notes, also rightly, that HTML5 allows
class attributes (as well as all other global attributes) on the
html element. One more reason to switch over to the HTML5 doctype, if you ask me.