Javascript Dom树遍历

来源:互联网 发布:淘宝刷真实流量软件 编辑:程序博客网 时间:2024/06/04 04:15
Node接口定义的节点类型都包含的特性和方法
特性和方法后面的 “冒号:” 紧跟的单词是“返回值类型 ”

Node 

属性

遍历节点(短途旅行):

parentNode : Node
firstChild : Node 
lastChild : Node 
nextSibling : Node 
previousSibling : Node 
childNodes : NodeList 

节点信息: 

nodeName :String 
nodeType :number 
nodeValue :String 

返回一个节点的根元素(文档对象): 

ownerDocument : Document 

包含了代表一个元素的特性的Attr对象;仅用于Element节点: 

attributes : NamedNodeMap 

获取对象层次中的父对象: 

parentElement [IE] :Node 

方法 

修改文档树: 

appendChild(Node newChild) : Node 
insertBefore(Node newChild, Node refChild) : Node 
removeChild(Node oldChild): Node 
replaceChild(Node newChild, Node refChild) : Node 

克隆一个节点: 

cloneNode(boolean deep) : Node 

删除一个子节点: 

removeNode(boolean removeChildren) : Node 

判断childNodes包含是否包含节点: 

hasChildNodes() : boolean


Document 

属性 

自己的: 

documentElement : Element 

继承 Node : 

attributes, childNodes, firstChild, lastChild, nextSibling, nodeName, nodeType, nodeValue, ownerDocument, parentElement, parentNode, previousSibling 

方法 

自己的: 

创建元素: 
createElement(String tagName) : Element 
createTextNode(String data) : Text 
查找元素: 
getElementById(String elementId) : Element 
getElementsByTagName(String tagname) : NodeList 

继承 Node : 

appendChild, cloneNode, hasChildNodes, insertBefore, removeChild, removeNode, replaceChild




Element 

属性 

自己的: 

tagName: String 

继承 Node : 

attributes, childNodes, firstChild, lastChild, nextSibling, nodeName, nodeType, nodeValue, ownerDocument, parentElement, parentNode, previousSibling 

方法 

自己的: 

属性的读写: 
getAttribute(String name) : String 
setAttribute(String name, String value) : void 
其它: 
getElementsByTagName(String name) Stub : NodeList 
normalize() Stub : void 
removeAttribute(String name) : void 

继承 Node : 

appendChild, cloneNode, hasChildNodes, insertBefore, removeChild, removeNode, replaceChild