我想在 <html>
中添加一个类元素并在 <head>
中运行它的代码元素。最好的方法是什么?
document.getElementsByTagName('html')[0].className = 'class';
或
document.documentElement.className = 'class';
最佳答案
这两种方法都不是真正的“更好”,但 documentElement
稍微快一点,因为它不必运行匹配函数,所以请使用它。
关于javascript - 访问 <html> 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6194983/