选择器
var div1 = document.getElementById("div");
var div2 = document.getElementsByTagName("div")[0];
var div3 = document.getElementsByClassName("div")[0];
var div4 = document.getElementsByName("div")[0];
var div5 = document.querySelector(".div>span");
var div6 = document.querySelectorAll(".div");
DOM基本操作
1,getElementById方法定义在Document.prototype上,
即ELement节点上不能使用。
2,getElementsByName方法定义在HTMLDocument.prototype
,即非HMTL中的docment不能使用(xml document,Element)
3, getElementsByTagNmae方法定义在Document.prototype
和Element.prototype上
4,HTMLDocument.prototype定义了一些常用的属性,body,head,分别指代
HTML文档中的body head标签。
5,Document.prototype上定义了document属性,指代文档的根元素,在HTML
文档中,它总是指代html元素
6,getELementsByClassName,querySelector
querySelectorAll在Document.prototype,Element.prototype
类中均有定义
var div = document.createElement('div');
var text = document.createTextNode('text');
var comment = document.createComment("this is comment");
document.body.appendChild(div);
oDiv.insertBefore(strong, span)
var a= oDiv.removeChild(strong);
oDiv.remove();