常用DOM方法和屬性 小結
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
最後更新:2017-04-03 15:21:56