The replaceChildren of ParentNode for JS replaces all the children of the node with nodes, while replacing the strings in the nodes with equivalent text nodes.
node.replaceChildren(nodes) Objects that implement Node. Nodes participate in a tree, which is known as the node tree.
<!doctype html>
<html>
<body>
<button>button</button>
<div>
<p>paragraph</p>
<p>paragraph</p>
<p>paragraph</p>
</div>
<script>
function myfunction()
{
document.querySelector("div").replaceChildren("replaceChildren");
}
document.querySelector("button").addEventListener("mouseover", myfunction);
</script>
</body>
</html>
<!doctype html>
<html>
<body>
<button>button</button>
<div>
<p>paragraph</p>
<p>paragraph</p>
<p>paragraph</p>
</div>
<script>
function myfunction()
{
document.querySelector("div").replaceChildren();
}
document.querySelector("button").addEventListener("mouseover", myfunction);
</script>
</body>
</html>
<!doctype html>
<html>
<body>
<button>button</button>
<div>
<p>paragraph</p>
<p>paragraph</p>
<p>paragraph</p>
</div>
<script>
function myfunction()
{
const myelement = document.createElement("p");
myelement.append("element");
document.querySelector("div").replaceChildren(myelement);
}
document.querySelector("button").addEventListener("mouseover", myfunction);
</script>
</body>
</html>