<!DOCTYPE html>
<html>
<body>
<h1>The Element Object</h1>
<h2>The replaceChild() Method</h2>
<ul id="myList">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<p>Click "Replace" to replace the first item in the the list.</p>
<button onclick="myFunction()">"Replace"</button>
<p>This example replaces the Text node "Coffee" with a Text node "Water". Replacing the entire li element is also an alternative.</p>
<script>
function myFunction() {
const element = document.getElementById("myList").children[0];
const newNode = document.createTextNode("Water");
element.replaceChild(newNode, element.childNodes[0]);
}
</script>
</body>
</html>