asp.net.ph

Skip Navigation Links

cloneNode Method

DHTML Methods


DOM Level 1 Specification.

Creates a new node that is an exact clone of this node.

Syntax

oClone = object.cloneNode ( true | false ) 
Parameters

false Optional. Cloned objects do not include childNodes.
true Optional. Cloned objects include childNodes.

Return Value

Returns an object referring to the newly created cloned node.

Remarks

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.

Example

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 

See Also

appendChild, insertBefore



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note