DHTML Methods
DOM Level 1 Specification.
Creates a new node that is an exact clone of this node.
oClone = object.cloneNode ( true | false )
false |
Optional. Cloned objects do not include childNodes. |
true |
Optional. Cloned objects include childNodes. |
Returns an object referring to the newly created cloned node.
The boolean flag indicates whether to recursively clone all nodes that are descendants of this node. If false
, clone this node and its attributes only. If true
, create a clone of the complete tree below this node; the cloneNode method copies the object, attributes, and all childNodes.
The cloned node has the same property values as the copied node for the following properties: nodeName, nodeValue, nodeType, parentNode, ownerDocument, and ( if it is an element ) attributes. The value of the clone's childNodes property depends on the setting of the boolean flag parameter.
Referring to the ID of an element that is cloned and added to the document hierarchy returns a collection.
The following sample demonstrates the use of the cloneNode method to copy an unordered list and its childNodes.
<script language="JavaScript">
function fnClone ( ) {
var oCloneNode=oList.cloneNode ( true );
document.body.insertBefore ( oCloneNode );
}
</script>
<ul id=oList>
<li>List node 1
<li>List node 2
<li>List node 3
</ul>
<input type=button value="Clone List"
onclick="fnClone ( )">
Show me
appendChild, insertBefore