DOM继承树,DOM基本操作

关系
document ---> HTMLDocument.prototype ---> Document.prototype
创建节点

document.createElement();
document.createTextNode();
document.createComment();
document.createDocumentFragment();

PARENTNODE.appendChild();
PARENTNODE.insertBefore(a, b):

parent.removeChild();
替换
parent.replaceChild(new, origin);

Element节点的一些属性
innerHTML
innerText(火狐不兼容) / textContent(老版本IE不好使)
Element节点的一些方法
ele.setAttribute()
ele.getAttribute();
用js写html标签

    var div=document.createElement('div');
        div.setAttribute('class','example');
        var p = document.createElement('p');
        p.setAttribute('class','slogan');
        p.innerText='查收的方法';
        div.appendChild(p);
        document.body.appendChild(div);

封装函数insertAfter();功能类似insertBefore();
insertAfter(添加元素 在谁的后面添加) insertBefore(添加元素 在谁的前面添加)

你可能感兴趣的:(DOM继承树,DOM基本操作)