节点属性
nodeName
- 元素节点的nodeName 是大写
只读不可修改
var div = document.getElementByTagName('div')[0]console.log(div);

nodeValue
文本节点
- 属性节点
- 注释节点
- 元素节点没有nodeValue
- 可修改
-
nodeType
元素节点 1
- 属性节点 2
- 文本节点 3
- 注释节点 8
- documen 9
- DocumeFragment 11
- 只读
-
attributes,getAttributes
可修改
-
hasChildNodes
有没有子节点
- 文本节点包含在内,换行在内
- 返回值 布尔值
封装
//获取某个节点下的所有子节点//遍历节点的节点类型function elemChild(node){var arr = [],//存放数组children =node.childNodes;//节点下的所有子节点for(var i = 0;i < children.length; i++){if(children[i].nodeType === 1){//如果节点下的字节点是元素节点就push到arr;arr.push(children[i]);}}return arr;}
类数组
//类数组function elemChildren(node){var temp = {'length':0,//长度初始化为0'push':Array.prototype.push,//添加一个数组原型上的push方法'splice':Array.prototype.splice// 添加一个数组原型上的splice方法},len = node.childNodes.length;for(var i = 0; i<len; i++){var children = node.childNodes[i];if(children.nodeType === 1){// temp[temp['length']] = children// temp['length']++;// 使用push的时候 length会自动++temp.push(children);}}return temp;}
Document
- 构造函数
-
DOM 树结构
Document
- HTMLDocument
-
Charactor
Text
-
Element
HTMLElement
-
DOM 操作
getElementById
定义在Document.prototype上
-
getElementByName
-
getElementByClassName,getElementByTagName,querySelector querySelectorAll
Document.prototype有
-
通配符 *
head,body
HTMLDocument.prototype->body,head
- 可以通过document直接访问
-
document.documentElement
Document.prototype->documentElement
- 获取整个html文档
