常用DOM方法和属性 小结

来源:互联网 发布:开淘宝店培训 编辑:程序博客网 时间:2024/05/21 14:50

DOM主要方法

查找节点

element = document.getElementById(id)

elements = document.getElementsByTagName(tagName)

attributeValue = element.getAttribute(attributeName)

booleanValue = element.hasChildNodes()

创建节点

reference = document.createElement(element)

reference = document.createTextNode(text)

复制节点

reference = node.cloneNode(booleanValue)

插入节点

element.appendChild(newChild)

element.insertBefore(newNode, targetNode)

替换节点

element.replaceChild(newChild, oldChild)

设置节点属性

element.setAttribute(attributeName, attributeValue)

删除节点

element.removeChild(node)

DOM属性

节点属性

nodeName

nodeType

nodeValue

遍历节点树

childNodes

firstChild

lastChild

nextSibling

previousSibling

parentNode

 

 

 

 

 

原创粉丝点击