使用: Node.prototype.replaceChild(newChild, oldChild);

var divA = document.getElementById('divA'); 
 
var newSpan = document.createElement('span'); 
newSpan.textContent = 'Hello World!'; 
 
divA.parentNode.replaceChild(newSpan, divA);

 

评论关闭
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!