The removeChild()
method removes a child node from an element.
It returns the removed node as a Node object, or null if the node does not exist.
removeChild |
Yes | Yes | Yes | Yes | Yes |
node.removeChild(node)
Parameter | Type | Description |
---|---|---|
node | Node object | Required. The node object to remove |
It returns the removed node as Node object.
The following code shows how to remove an item from a list.
<!DOCTYPE html>
<html>
<body>
<!-- w w w .j a v a 2 s . com-->
<ul id="myList"><li>A</li><li>B</li><li>C</li></ul>
<button onclick="myFunction()">test</button>
<script>
function myFunction()
{
var list=document.getElementById("myList");
list.removeChild(list.childNodes[0]);
}
</script>
</body>
</html>
The code above is rendered as follows: