How to get html element's class tags

Steven Lu picture Steven Lu · Jul 14, 2012 · Viewed 46.8k times · Source

I'm using a custom modernizer config which has selected the features I employ in my page (and only those features).

So, I'd like to simply grab the className of the <html> of the page so I can check to see how many no- prefixed classes are present (maybe checking classlist.match(/no-/g).length) and determine if my javascript should just give up.

It's not clear whether I should use

document.getElementsByTagName('html').className

or

$('html').attr('class')

or

document.documentElement.className

Answer

ZER0 picture ZER0 · Jul 14, 2012

I will go for:

document.documentElement.className;

Because doesn't involve any function's call, neither an additional layer like jquery. Ideally this one is the cleanest and the fastest.