dom选择器和节点类型
document.getElementById()方法定义在Document.prototype上,所以Element节点上不能使用
document.getElementsByName()方法定义在HTMLDocument.prototype上,即非html中的document不能使用
document.getElementsByTagName() , document.getElementsByClassName()方法定义在Document.prototype上和HTMLDocument.prototype上
HTMLDocument.prototype定义了一些常用的属性,body,head分别指代html文档中的body标签和head标签
Document.prototype上定义了documentElement属性,指代文档的根元素,在heml文档中他总是指代html元素
document.querySelector("div>ul>li")//按照css选择器的语法选择(选择一个)
document.querySelectorAll()选择一组
但是这两个选择器不是实时选择的,所以基本不用
节点
parentNode 父节点 html的parentNode是#document
childNode 子节点们(包括,文本节点,元素节点,属性节点,注释节点)
firstChild 第一个子节点
lastchild最后一个子节点
nextSibling后一个兄弟节点
previous Sibling前一个兄弟节点
基于元素节点的遍历
parentEment 返回当前元素的父元素节点(IE不兼容)
children 只返回当前元素的子节点
node.childElementCount===node.children..length当前元素节点的子元素节点个数
firstElementChild 第一个元素节点lastElementchild最后一个子元素节点
nextElementSibling 后一个兄弟节点
节点属性
nodename 节点名字(元素标签名大写只读)
nodeValue 文本(text)节点和注释(Comment)节点的文本内容,可以读写
nodetype:节点类型(只读)返回值1.元素节点 2.属性节点 3.文本节点 8。注释节点 9.document 11.Document Fragment(文档碎片节点)
attributes 元素节点的属性节点集合