Javascript Reference - HTML DOM removeChild Method








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.

Browser Support

removeChild Yes Yes Yes Yes Yes

Syntax

node.removeChild(node)

Parameters

Parameter Type Description
node Node object Required. The node object to remove




Return Value

It returns the removed node as Node object.

Example

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: