How do you add a class to the <html> root element using Javascript?
How do you add a class to the <html> root element using Javascript?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Like this:
Or use this as your ‘setter’ line to preserve any previously applied classes: (thanks @ama2)
Or, depending on the required browser support, you can use the
classList.add()method:https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
http://caniuse.com/#feat=classlist
UPDATE:
A more elegant solution for referencing the
HTMLelement might be this: