Removes a child node from a node.
Syntaxvar removedNode = node.removeChild();
Parameters oldChild
The node to be removed from the document.
Return ValueReturns an object of type DOM NodeDOM Node
The removed node.
ExamplesThis 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 specificationsMozilla Developer Network : [Node.removeChild Article]
Microsoft Developer Network: [removeChild Method Article]
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