A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/dom/Node/cloneNode below:

cloneNode ยท WebPlatform Docs

cloneNode Summary

Copies a reference to the object from the document hierarchy.

Method of dom/Nodedom/Node

Syntax
var clonedNode = node.cloneNode();
Parameters cloneDescendants
Data-type
Boolean

Whether to clone the child nodes of the node as well.

Return Value

Returns an object of type DOM NodeDOM Node

The cloned node.

Examples
<!doctype html>
<script>
function fnClone(){
   
   var oCloneNode = document.getElementById("oList").cloneNode(true);
   
   document.body.insertBefore(oCloneNode);
}
</script>
<ul id="oList">
<li>List node 1</li>
<li>List node 2</li>
<li>List node 3</li>
<li>List node 4</li>
</ul>
<input type="button" value="Clone List" onclick="fnClone()">
Usage
 Use this method to copy an node, its attributes and, if specified, its childNodes as well.
Notes

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.

<!doctype html>

<html>

<script>
function fnBegin(){
    var fr = document.getElementByid("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.

Related specifications
DOM Level 3 Core
Recommendation
Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4