cloneNode method

[This documentation is preliminary and is subject to change.]

Copies a reference to the object from the document hierarchy.

Document Object Model (DOM) Level 3 Core Specification, Section 1.4

Syntax

IHTMLDOMNode retVal = object.cloneNode(fDeep);

Standards information

Parameters

fDeep [in, optional]

Type: VARIANT_BOOL

VARIANT_BOOL that specifies one of the following values:

VARIANT_FALSE (FALSE)

Cloned objects do not include childNodes.

VARIANT_TRUE (TRUE)

Cloned objects include childNodes.

Remarks

The cloneNode method copies an object, attributes, and, if specified, the childNodes.

When you refer to the ID of a cloned element, a collection is returned.

cloneNodedoes not work on an IFRAME directly. You must call cloneNodethrough the all collection. The following example demonstrates how to call cloneNode on an IFRAME.

<HTML>
<SCRIPT>
function fnBegin(){
    var fr = document.all.oFrame.cloneNode();
    console.log(document.body.innerHTML);
}    
</SCRIPT>
<BODY onload="fnBegin()">
    <IFRAME id="oFrame" src="about:blank" 
        style="border:1px solid black; position:absolute; top:20px; left:30px;
            width:350px; height:300px;"></IFRAME>
</BODY>    
</HTML>

If the object being cloned is an element and that element has expandos defined on it, the expandos are copied to the clone when cloneNode is called. Other browsers might handle this differently.

In Microsoft Internet Explorer 6, this method applies to the attribute object.

See also

Reference

appendChild

removeNode

replaceNode

swapNode

 

 

Build date: 1/26/2012