How do I add the class name "foo" to the root <html> element without using jQuery (or a similar library)?
<html>
You can use the classList to access an element's list of classes.
document.documentElement.classList.add('my-awesome-class'); document.documentElement.classList.remove('my-awesome-class'); document.documentElement.classList.contains('my-awesome-class');
2.1m questions
2.1m answers
60 comments
56.9k users