Name

Node.cloneNode( ) — duplicate a node and, optionally, all of its descendants

Availability

DOM Level 1 Core

Synopsis

Node cloneNode(boolean deep);

Arguments

deep

If this argument is true, cloneNode( ) recursively clones all descendants of this node. Otherwise, it clones only this node.

Returns

A copy of this node.

Description

The cloneNode( ) method makes and returns a copy of the node on which it is called. If passed the argument true, it recursively clones all descendants of the node as well. Otherwise, it clones only the node and none of its children. The returned node is not part of the document tree, and its parentNode property is null. When an Element node is cloned, all of its attributes are also cloned. Note, however, that EventListener functions registered on a node are not cloned.

Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.