jQuery .clone() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DOM

Definition

.clone() creates a deep copy of matched elements (and their descendants) since jQuery 1.0. The original stays in place — chain .appendTo() or similar to insert the copy.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$(".hello").clone().appendTo(".goodbye")  // copy, then insert
$(".hello").appendTo(".goodbye")          // moves — original leaves

.clone()           // structure only (default)
.clone(true)       // + events and .data() (1.4+)
.clone(true, true) // + events/data on children (1.5+)
CallWhat it does
.clone()Learn jQuery .clone(): deep-copy elements and descendants, optional events and data, clone vs move, duplicate id pitfalls, examples, and FAQs.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select the element(s) you want to duplicate.
Step 2Call .clone() or .clone(true) / .clone(true, true) as needed.
Step 3Optionally change attributes (especially id) on the clone.

Return Value

Return ValueDescription
BooleanOften true or false depending on the match or state.
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Clone Then Insert

Copy bold text and prepend the clones into paragraphs.

jQuery
$("b").clone().prependTo("p");
Try It Yourself

How It Works

  1. Select. $("b") finds every bold element.
  2. Clone. .clone() deep-copies those nodes (structure only).
  3. Insert. .prependTo("p") puts each copy at the start of every paragraph.

Example 2 — Clone vs Move

Same insertion API — with and without .clone().

jQuery
$(".hello").clone().appendTo(".goodbye"); // copy
// $(".hello").appendTo(".goodbye");      // would move instead
Try It Yourself

How It Works

  1. Clone path. Copy first, then append — two Hello nodes exist.
  2. Move path. Append alone relocates the original node.
  3. Rule. Need both? Clone. Need relocate? Skip clone.

Example 3 — Clone With Events

Pass true so click handlers come along.

jQuery
$("#btn").on("click", function () {
  $("#out").text("clicked");
});

$("#btn").clone(true).appendTo("#tray");
// clone(true) keeps the click handler
Try It Yourself

How It Works

  1. Bind. A click handler is attached to #btn.
  2. clone(true). Copies the element plus events and .data().
  3. Insert. The copy is appended into #tray.

Frequently Asked Questions

.clone() creates a deep copy of the matched elements, including descendants and text nodes. The original stays put. Chain an insertion method such as .appendTo() or .insertAfter() to place the copy. Available since jQuery 1.0.
Appending an element already in the document moves it. Calling .clone() first copies it, so the original remains and the copy is inserted.
By default, no. Use .clone(true) to copy event handlers and (since 1.4) .data() values. As of 1.5, a second argument deepWithDataAndEvents controls whether children also get events and data.
The optional second Boolean (jQuery 1.5+) copies events and data on all descendants. By default it matches the first argument. Use .clone(true, true) for the element and its children.
Cloning copies attributes, including id. IDs must be unique. Change the clone’s id (and related for/aria hooks) before inserting, or prefer classes for elements you plan to duplicate.
For input elements, typed text and checkbox state are generally kept. For performance, user data in textarea and selections on select are not copied — re-apply those values if needed.
No. Arrays and objects inside .data() are shared between the original and the clone. Deep-copy them manually with something like $.extend([], arr) when needed.

Next: .insertAfter() Method

Insert matched elements after a target with content-first syntax.

.insertAfter() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful