doc: create a DOM traversal methods
This commit is contained in:
1 parent
14c9c20f28
commit
66fda65335
1 file changed
+10
@@ -104,3 +104,13 @@ id("info").replaceChild(child, qs("#info h2"));
|
||||
| parent.replaceChild(new, old) | 用新节点替换给定的子节点 |
|
||||
| parent.insertAdjacentElement(location, new) | 在相对于父元素的给定位置插入新元素 |
|
||||
|
||||
## DOM遍历方法
|
||||
我们可以使用DOM树来遍历父/子/兄弟关系(例如从父节点中删除一个元素)。每个节点的DOM对象都有以下(只读)属性来访问树中的其他DOM节点:
|
||||
| 名称 | 描述 |
|
||||
| ----------- | ----------- |
|
||||
| firstElementChild, lastElementChild | 该节点子元素列表的开始/结束 |
|
||||
| children | 该节点的所有子节点的数组(与包含文本的childNodes不同) |
|
||||
| nextElementSibling, previouElementSibling | 具有相同父节点的相邻元素节点,跳过空白节点 |
|
||||
| parentNode (parentElement) | 包含节点的元素 |
|
||||
|
||||
这些是我们将看到的常见遍历属性,但是您可以在[这里](https://developer.mozilla.org/zh-CN/docs/Web/API/Node)找到一个完整的列表
|
||||
Reference in new issue
Block a user