Reputation: 1128
I'd like to add a class to the <html>
element and run the code for it in the <head>
element. What's the best way to do that?
document.getElementsByTagName('html')[0].className = 'class';
or
document.documentElement.className = 'class';
Upvotes: 3
Views: 1392
Reputation: 21249
Modernizr seems to use document.documentElement (by looking at the source).
I guess that's a good reference :)
Upvotes: 3
Reputation: 6949
Neither way is really 'better', but documentElement
is a tiny bit faster, because it doesn't have to run the matching function, so go with it.
Upvotes: 4