<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>replaceChild 实现子节点(对象)的替换</title>
</head>
<body>
<script type="text/javascript">
function replaceMessage(){
var newnode=document.createElement("p");
var newnodeText=document.createTextNode("JavaScript");
newnode.appendChild(newnodeText);
var oldnode=document.getElementById("oldnode")
oldnode.parentNode.replaceChild(newnode,oldnode); //这里用到了parentNode
}
</script>
<h1 id="oldnode">Java</h1>
<a href="javascript:replaceMessage()">"Java"替换"JavaScript"</a>
</body>
</html>