添加和删除节点

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>添加和删除节点</title>
</head>
<body>
<div id="div1">
<p id="p1">这是一个段落</p>
<p id="p2">这是第二个段落</p>
</div>
<script>
var para = document.createElement('p');
var node = document.createTextNode('这是我又创建的另一个新元素');
para.appendChild(node);
var element = document.getElementById('div1');
var child = document.getElementById('p2');
// element.appendChild(para);
// element.insertBefore(para,child);
// element.removeChild(child);

// var child=document.getElementById("p1");
parent.replaceChild(para,child);
</script>
</body>
</html>

原文地址:https://www.cnblogs.com/studyh5/p/8006341.html