简体   繁体   English

如何将CSS类添加或应用到整个HTML

[英]How to add or apply a CSS class to an entire HTML

I usually add a class to the body of an HTML document like this: 我通常将一个类添加到HTML文档的主体中,如下所示:

document.body.classList.toggle('darkClass', this.props.isDark)

But I am not sure how to get the entire html element. 但是我不确定如何获取整个html元素。 How can I reference it in Javascript? 如何在Javascript中引用它?

var html = ?
html.classList.toggle(...)

You can use document.documentElement to get the entire html element. 您可以使用document.documentElement来获取整个html元素。 And also see it's innerHTML property. 还可以看到它的innerHTML属性。

 console.log(document.documentElement); 
 <html> <head> </head> <body> <div>TEST</div> </body> </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM