
1.DOM--document object model
常用的节点类型:
元素节点;(标签)
属性节点;(标签里的属性)
文本节点;(文本节点)
2,document有个属性叫nodetype,返回的是数字
代表元素节点;属性节点;文本节点
3,节点的获取:
元素节点--
document.getelementById()
document.getelementsByTagName()
document.getelementsByClassName()
document.queryselector()
document.queryselectorall()
属性节点--
ys.attributes 获取元素身上的所有属性构成的集合
ys.attributes[i].value 得到属性集合里面的值
ys.getAttribute(“属性名”) 获取属性值的方法
ys.setAttribute(“属性名”,“属性值”) 给元素设置属性,属性值
ys.removeAttribute(“属性”)删除属性
文本节点--
4,获取元素子节点:
元素.childNode 这个属性有兼容性,标准浏览器会获取到文本节点
元素.children 低版本(建议使用)
5,获取父节点:
元素.parentNode(没兼容性)
区分offsetparent和parentnode区别:
offsetparent(position:relative/absolute)
offsetNode(父节点)
DOM --动态创建节点:
1,生成节点的方法:
document.createElement(“div”)
2,插入节点:
父元素.appendChild(新节点) 在父元素的子节点后面插入新节点
3,在指定位置插入新的节点
父元素.inSertBefore(新节点;谁的前面) 将新节点插入指定元素前面
4,删除元素节点:
父元素.removerChild()