Remove the last node from its parent in JavaScript
Description
The following code shows how to remove the last node from its parent.
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 w w w .j a v a 2 s . c om-->
</div>
<p id="p1">Hello <b>World!</b></p>
<script type="text/javascript">
var div = document.getElementById("div1");
var p = document.getElementById("p1");
var formerLastChild = div.removeChild(div.lastChild);
document.writeln(formerLastChild);
</script>
</body>
</html>
The code above generates the following result.
Javascript Tutorial Delete
Remove a child element from a HTML element ...
Remove node from another node in Javascript...
Remove a child element from a HTML element ...
Remove node from another node in Javascript...