Latest web development tutorials

HTML DOM cloneNode method

Elements Object Reference Element object

Examples

A copy of a list item to another list:

var node=document.getElementById("myList2").lastChild.cloneNode(true);
document.getElementById("myList1").appendChild(node);

Before copying:

  • Coffee
  • Tea
  • Water
  • Milk

After the copy:

  • Coffee
  • Tea
  • Milk
  • Water
  • Milk

try it"

Definition and Usage

cloneNode () method to create an exact copy of the specified node.

cloneNode () method to copy all the attributes and values.

This method will copy it and return to the calling node copy. If the parameters passed to it is true, it will recursively copy all descendants of the current node. Otherwise, it copies only the current node.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support cloneNode () method


grammar

node.cloneNode(deep)

parameter

参数 类型 描述
deep Boolean 可选。该方法将复制并返回调用它的节点的副本。如果传递给它的参数是 true,它还将递归复制当前节点的所有子孙节点。否则,它只复制当前节点。

return value

类型 描述
节点对象 拷贝的节点

technical details

DOM version Core Level 1 Node Object


Elements Object Reference Element object