A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/dom/Node/removeChild below:

removeChild ยท WebPlatform Docs

removeChild Summary

Removes a child node from a node.

Method of dom/Nodedom/Node

Syntax
var removedNode = node.removeChild();
Parameters oldChild
Data-type
Blob

The node to be removed from the document.

Return Value

Returns an object of type DOM NodeDOM Node

The removed node.

Examples

This example uses the removeChild method to remove a bold element from a div.

<!doctype html>
<html>
<head>
<script type="application/javascript">
function removeElement()
{
  var div1 = document.getElementById("Div1");
  try
  {
      
    var oChild=div1.children(0);
    div1.removeChild(oChild);
  }
  catch(x)
  {
    alert("You have already removed the bold element.\nPage will be refreshed when you click OK.")
    document.location.reload();
  }
}
</script>
</head>
<body>
<div id="Div1" onclick="removeElement()">
Click anywhere in this sentence to remove this <strong>Bold</strong> word.
</div>
</body>
</html>

Remove all children from a node.

while (element.lastChild) {
  element.removeChild(element.lastChild);
}
Notes

The node to be removed must be an immediate child of the parent node. This method is accessible at run time. If elements are removed at run time, before the closing tag is parsed, areas of the document might not render.

Related specifications
DOM Level 3 Core
Recommendation
Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4