![](https://img.haomeiwen.com/i2508642/5e869128138bbc91.png)
![](https://img.haomeiwen.com/i2508642/da0e22c44e93fa66.png)
![](https://img.haomeiwen.com/i2508642/63255b7695f8a226.png)
节点操作
获取节点
getElementById
element = document.getElementById(id)
getElementsByTagName
collection = element.getElementsByTagName(tagName)
返回值为动态的集合
getElementsByClassName
collection = element.getElementsByClassName(className)
兼容性解决
![](https://img.haomeiwen.com/i2508642/ad53325f49fbe5bc.png)
querySelector/All
list = element.querySelector/All(selector)
Selector获取第一个元素,All获取所有元素
list不是动态的集合,一旦获取到,就不会改变
![](https://img.haomeiwen.com/i2508642/7ffe5919d1935e2a.png)
创建节点
element = document.creatElement(tagName)
修改节点
element.textContent
节点及其后代节点中的文本内容
element·.innerText
ff不支持
兼容性解决
![](https://img.haomeiwen.com/i2508642/d7db8949fb085f27.png)
插入节点
appendChild
var a = element.appendChild(achild) 在指定元素后添加节点
insertBefore
var a = element.insertBefore(achild,reference) 在指定元素最前面插入节点
删除节点
removeChild
child = element.removeChild(child)
innerHTML
element.innerHTML
节点的HTML内容
会有内存泄漏,安全问题
网友评论