How to get class list of the <HTML> element?

Issue

I would like to access the class list of the html element (that is in this case I’d like to know if my-class is set on html):

<html class="my-class">
...
</html>

How can I do that with JavaScript?

Solution

Select the element and then classList:

document.querySelector('html').classList or if you have multiple clsases in your element then you can select by class to get the other classes from this element too.
document.querySelector('.my-class').classList

Answered By – Maik Lowrey

Answer Checked By – Jay B. (AngularFixing Admin)

Leave a Reply

Your email address will not be published.