JavaScript Reference/Javascript Methods/removeChild
"removeChild()" Example
<source lang="javascript">
<html> <body> <script language="JavaScript"> function function2() {
var m = "New Element"; var n = document.createElement("li"); n.appendChild(document.createTextNode(m)); document.getElementById("myList").appendChild(n);
} function function2() {
myList.removeChild(myList.lastChild);
} </script>
- First list element
- Second list element
<input type="button" value="Add list item" onClick="function2();"> <input type="button" value="Remove added items" onClick="function2();"> </body> </html>
</source>
"removeChild()" is applied to
<source lang="javascript">
+----------------+--------------------------------------------------------------+ | Applied_To |<a> <acronym> | | |<address> <applet> | | |<area> attribute | | | <base> | | |<basefont> |
| ||| |<body>
| | |<button>| | | | | |
| |<col> | | |<colgroup> <comment> | | |
| | | <dir> ||
| |
- | | |<fieldset> | | |<form> <frame> | | |<frameset> <head> | | |<hn>
|| |<html> | | |<iframe> <img> | | |<input> <input type="button"> | | |<input type="checkbox"> <input type="file"> | | |<input type="hidden"> <input type="image"> | | |<input type="password"> <input type="radio"> | | |<input type="reset"> <input type="submit"> | | |<input type="text"> | | |<isindex> | | |<label> <legend> |
| |- <link> | | |<listing> <map> | | |<marquee> <menu> | | |<meta> <noframes> | | |<noscript> <object> | | |
<optgroup> | | |<option>
| | |<param> <plaintext> | | |
| | || | |<script> <select> | | | | | || | |<style> | | || | |<tbody>
| | |<textarea> <tfoot> |
| |<thead> | | |<title> | | | | | | | | |<xmp> | +----------------+--------------------------------------------------------------+ </source>
"removeChild()" Syntax, Parameters and Note
<source lang="javascript"> Note: Removes a child node created by the createTextNode() method.
Syntax:
document.getElementById("elementID").removeChild(param1) document.all.elementID.removeChild(param1) // IE only Parameters: param1 Required; the name of the element to be removed.
</source>