Replace a child : Replace : DOM Node JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » DOM Node » Replace »

 

Replace a child

















<html>
<head>
<title>replaceChild() Example</title>
<script type="text/javascript">
    function replaceMessage() {
        var oNewP = document.createElement("p");
        var oText = document.createTextNode("www.navioo.com");
        oNewP.appendChild(oText);
        var oOldP = document.body.getElementsByTagName("p")[0];
        oOldP.parentNode.replaceChild(oNewP, oOldP);
    }
</script>
</head>
<body onload="replaceMessage()">
<P>A</p>
<P>C</p>
<P>D</p>
</body>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo DOM Node
» Replace