Access <html> node

I would like to add a class to the element <html>and run the code for it in the element <head>. What is the best way to do this?

document.getElementsByTagName('html')[0].className = 'class';

or

document.documentElement.className = 'class';

+3
source share
2 answers

None of the methods is “best,” but a documentElementlittle faster, because it does not need to run the corresponding function, so go with it.

+4
source

Modernizr seems to be using document.documentElement (looking at the source).

I think a good link :)

+3
source

All Articles