Search code examples
javascriptjqueryhtmlcssmodernizr

How to get html element's class tags


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

Solution

  • 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.