Element removeChild Method - Javascript DOM

Javascript examples for DOM:Element removeChild

Description

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.

Parameter Values

Parameter TypeDescription
node Node object Required. The node object you want to remove

Return Value:

A Node object, representing the removed node, or null if the node does not exist

The following code shows how to Remove the <span> element.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>


<div id="myDIV">
  <span id="mySpan" style="font-size:35px;">A Span element</span>
</div>/*from  w  w  w .jav  a 2  s . c  o m*/

<button onclick="removeSpan()">Remove span</button>

<script>
var child = document.getElementById("mySpan");

function removeSpan() {
    child.parentNode.removeChild(child);
}

</script>

</body>
</html>

Related Tutorials