Favorites

DOM Node.cloneNode() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Node.cloneNode()
DOM Node MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The cloneNode() method makes a copy of a node, optionally including all of its children.

Description

The cloneNode() method returns a copy of the node. With deep set to true, the whole subtree is copied too. Attributes are copied, but event listeners added with addEventListener() are not. Watch for duplicate id values in clones. It's commonly used to stamp out copies of a <template>'s content.

Without deep, only the node itself is copied: for an element that means its tag and attributes, but none of its content or children. Form controls copy their attribute values, but some current state, such as text typed into an input, may not be copied the same way in every browser, so set values explicitly on the clone if they matter.

The clone isn't part of any document until you insert it, and inline onclick attributes are copied because they're attributes. For copying elements from another document, such as a parsed template, document.importNode() is the equivalent method.

Syntax

node.cloneNode()
node.cloneNode(deep)

Parameters

  • deepOptional. true to copy all descendants as well. Defaults to false.

Return Value

The new copy of the node, which is not yet in the document.

Example

<div class="card" id="card"><h3>Original</h3><p>Body text</p></div>
const card = document.getElementById('card');
const copy = card.cloneNode(true);
copy.id = 'card-2';
copy.querySelector('h3').textContent = 'Copy';
card.after(copy);
console.log(document.querySelectorAll('.card').length);

Browser Support

The following information will show you the current browser support for the Node.cloneNode() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee