JavaScript Reference/Javascript Methods/cloneNode
"cloneNode()" Example
<source lang="javascript">
<html> <body> <script language="JavaScript"> function function1(){
var myNode = myButton.cloneNode(true); alert(myNode.innerHTML);
} </script> <button id="myButton" onclick="function1();">Clone node</button> </body> </html>
</source>
"cloneNode()" is applied to
<source lang="javascript">
+----------------+--------------------------------------------------------------+ | Applied_To |<a> <acronym> | | |<address> <applet> | | |<area> attribute | | | <base> | | |<basefont> | | |<bgsound> |
| |<body> || |
| |
<button> || | |
| |<dir>| | |<col> <colgroup> | | |<comment>
| | | || | |
- | | | <embed> | | |<fieldset> | | |<form> <frame> | | |<frameset> <head> | | |<hn>
|| |<html> | | |<iframe> <img> | | |<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>
"cloneNode()" Syntax, Parameters and Note
<source lang="javascript"> Note: Creates a copy of the current node. After an element is cloned, referring to the id of that element returns a collection.
Syntax:
document.getElementById("elementID").cloneNode(param1) document.all.elementID.cloneNode(param1) // IE only
Parameters: param1 Optional; either true or false, indicating whether or not you want to clone child nodes as well.
</source>