DHTML Methods
DOM Level 1 Specification.
Removes a child node from an element.
object.removeChild ( oNode )
oNode |
Required. The element to be removed from the document. |
Returns the node removed.
The node to be removed must be an immediate child of the parent object. An exception occurs when oNode is not a child of this node, or when the specified oNode is read-only and cannot be removed.
This sample demonstrates removing a bold element from a div using the removeChild method.
Click anywhere in this sentence to remove this Bold word.
<div id=Div1 onclick="removeElement ( )">
Click anywhere in this sentence to remove this
<b>Bold</b> word.</div>
<script language="JavaScript">
function removeElement ( ) {
try {
var oChild=Div1.children ( 0 );
Div1.removeChild ( oChild );
}
catch ( x ) {
alert ( "You have already removed the bold element.
Page will be refreshed when you click OK." )
document.location.reload ( );}
}
</script>
appendChild, replaceChild