replaceChild 替换节点

    1. <div id="app">
    2. <p id="child">hello world</p>
    3. </div>
    4. <!-- 替换节点
    5. parentNode.replaceChild(newNode,targetNode); -->
    6. <script>
    7. var app=document.getElementById("app");
    8. var h1=document.createElement("h1");
    9. h1.innerHTML="change";
    10. var child=document.getElementById("child");
    11. app.replaceChild(h1,child);