DHTML Methods
Replaces the object with another element.
object.replaceNode ( oNewNode )
oNewNode |
Required. Specifies the new element to replace the object. |
No return value.
When a node is replaced, all values associated with the replaced object are removed. For example, if a B object is replaced with an I object, any attributes and text between the opening and closing tags are also replaced. To preserve these values, they can be copied to the new element before the original object is replaced.
The following sample demonstrates the use of the replaceNode method to replace an unordered list with an ordered list.
<script language="JavaScript">
function fnReplace ( ) {
var sPreserve = oList.innerHTML;
var oNewNode = document.createElement ( "OL" );
oList.replaceNode ( oNewNode );
oNewNode.innerHTML = sPreserve;
}
</script>
<UL ID = oList>
<LI>List Item 1
<LI>List Item 2
<LI>List Item 3
<LI>List Item 4
</UL>
<input TYPE = button VALUE = "Replace List"
onclick = "fnReplace ( ) ">
replaceChild