JavaScript Reference/Javascript Methods/replaceChild
"replaceChild()" Example
<source lang="javascript">
<html> <body> <script language="JavaScript"> function function1() {
var newElement = document.createElement("u"); newElement.innerHTML = "Text"; var oldElement = document.all.myBold; document.all.myDiv.replaceChild(newElement, oldElement);
} </script> <button onclick="function1();">Replace text</button>
text
</body> </html>
</source>
"replaceChild()" 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>
"replaceChild()" Syntax, Parameters and Note
<source lang="javascript"> Note: Replaces one element node with another.
Syntax:
document.getElementById("elementID").replaceChild(param1, param2) document.all.elementID.replaceChild(param1, param2) // IE only Parameters: param1 Required; the replacement element node. param2 Required; the element node to be replaced.
</source>