doc: createa replace Node on DOM Tree section

This commit is contained in:
Leon Xu committed 2021-09-08 19:39:30 -07:00
1 parent 43aa0228fa
commit bfd5333d04
1 file changed
+11
+11
View File
@@ -81,4 +81,15 @@ newHeading.textContent = "This is a new heading!";
let li = document.createElement('li');
li.textContent = "A list item!";
id("my-list").appendChild(li);
```
### 替换DOM树中的节点
| 名称 | 描述 |
| ----------- | ----------- |
| parent.replaceChild(newChild, oldChild) | 用新的子节点替换特定的子节点 |
```javascript
let child = document.createElement("h2");
child.textContent = "I am a new child!";
id("info").replaceChild(child, qs("#info h2"));
```