简体   繁体   English

可以在javascript中替换DOM中的根元素HTML

[英]Can the root element HTML in the DOM be replaced in javascript

I am a beginner in javascript. 我是javascript的初学者。 As mentioned in stack overflow query , I can remove or create elements within the DOM. 堆栈溢出查询中所述 ,我可以在DOM中删除或创建元素。 However, can I replace the root element through javascript eg if I want to change an attribute of the HTML element through javascript? 但是,我可以通过javascript替换根元素,例如,如果我想通过javascript更改HTML元素的属性?

I think you're asking if you can modify the element, and the answer is yes. 我想你问是否可以修改元素,答案是肯定的。

var html = document.getElementsByTagName('html')[0];
html.title = "Foo"; // Set an attr on the element

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

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