1、让JS 操作HTML 和 XML 的接口
任何元素都有 nodeType
记住 1元素节点 3文本节点 8注释节点 9 文档节点 document
基于元素节点树 遍历 children 可用 其他的如 parentElement firstElementChild lastElementChild ie9以下用不了
2、
document 继承自 HTMLDocument.prototype 继承自 Document.prototype
3、 dom 基本操作
1) getElementByid方法定义在Document.prototype上
2) getElementByName 方法定义在HTMLDocument.prototype上
3)getElementsByTagName方法定义在Document.prototype和Element.prototype上
document.body 就是 标签
document.head 就是 标签
4、document.documentElement 表示的是 HTML 特殊记录
5、增
<!DOCTYPE html>
<html lang = "en">
<head>
<title>修炼之路</title>
<meta charset="utf-8">
<style type="text/css">
</style>
</head>
<body>
<script type="text/javascript">
var div = document.createElement("div");
</script>
</body>
</html>
6、插
appendChild (剪切操作) 和 .push 一个意思
<body> <div></div>
<script type="text/javascript">
var div = document.getElementsByTagName("div")[0];
var text = document.createTextNode("吴宝宝");
var span = document.createElement("span");
div.appendChild(text);
div.appendChild(span);
var text1 = document.createTextNode("demo");
span.appendChild(text1);
</script>
</body>
解释一下
实现的效果如图
7、替换 使用的不多
parent.replaceChild(new , origin);
最常用 增 document.creatElement();
插 div.appendChild(); div 可以是其他的标签
div.insertBofore(a, b)
删除 p.remove();
child.remove();