编辑器
getElementById
getElementsByTagName
getAttribute
setAttributewhich.getAttribute("href");
var source = placeholder.setAttribute("src", "source")
document.write('<p>This is instered</p>')
兼容性
难点
处理的bug
最后更新于
document.createElement(nodeName)
docuemnt.createTextNode(text)
// 这是一个文本节点
document.createElement(n)
docuemnt.createTextNode("Hello world")
insertBefore()
1. 新元素
2. 目标元素: 想把新元素插入到哪个元素(targetElement)之前
3. 父元素
parentElement.insertBefore(newElement, targetElement)
targetElement 元素的parentNode 属性
function insertAfter(newElement, targetElment){
var parent = targetElement.parentNode;
if(parent.lastChild == targetElement){
parent.appendChild(newElement)
} else {
parent.insertBefore(newElement, targetElement.nextSibling)
}
}
// 删除
var el = document.getElementById('div-02');
el.remove();
// id 为 'div-02' 的 div 被删掉了
element.setAttribute('height', 100);
element.setAttribute('height', '100px');element.style['text-align'] = '100px';
element.style.height = '100px';element.setAttribute('height', 100);
element.setAttribute('height', '100px');element.setAttribute('style', 'height: 100px !important');
element.style.setProperty('height', '300px', 'important');element.className = 'blue';
element.className += 'blue fb';element.style.cssText = 'height: 100px !important';
element.style.cssText += 'height: 100px !important';