Remove node from another node in Javascript in JavaScript

Description

The following code shows how to remove node from another node in Javascript.

Example


<!DOCTYPE html>
<html>
<body>
<div id="div1">
<ul>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ul><!--from ww  w  .  java 2 s.c o m-->
</div>
<p id="p1">Hello <b>World!</b></p>


<script type="text/javascript">
var div = document.getElementById("div1");
var p = document.getElementById("p1");

var formerFirstChild = div.removeChild(div.firstChild);
document.writeln(formerFirstChild);

</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Remove node from another node in Javascript in JavaScript
Home »
  Javascript Tutorial »
    DOM »
      Delete
Javascript Tutorial Delete
Remove a child element from a HTML element ...
Remove node from another node in Javascript...
Remove the last node from its parent in Jav...