节点

1、节点类型:nodeType

元素节点(nodeType == 1)
属性节点(nodeType == 2 )
文本节点(nodeType == 3 )

。。。

2、节点值:nodeValue

3、节点名称:nodeName

4、操作节点

1)增:

createTextNode

creatElement

cloneNode(boolean) :true 包含子节点, false 不包含子节点,若有id,需要修改id值

appendChild,insertBefore

2)删

removeChild

xx.parentNode.removeChild

xx.parentElement.removeChild

3)改:

replaceChild

4)查

document.documentElement 根节点:<html>

document.body: <body>

childNodes:每个节点都有

parentNode:父节点

hasChildNodes( )

firstChild,lastChild

nextSibling,previousSibling

-----------------------------------

document.getElementById()
document.getElementsByClassName() // IE6
document.getElementsByTagName()
document.getElementsByName()
document.querySelector()
document.querySelectorAll()

5、树形结构:

class Node {
  constructor(val){
    this._val = val ;
    this._parent = null;
    this._children = [ ];
  }
}

posted @ 2019-12-04 20:57  雨夜稻草  阅读(373)  评论(0编辑  收藏  举报