jQuery .clone() Method

Beginner
7 min read
Updated: Oct 2026
4 examples
Live preview

What Is .clone()?

.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.

Remember
$(".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+)
NeedUse
Duplicate markup$(el).clone().appendTo(target)
Copy with click handlers$(el).clone(true)
Copy events on children too$(el).clone(true, true)
Move (no copy)$(target).append($(el))

How to Use .clone()

Copy first, optionally tweak the clone, then insert it.

  1. Select the element(s) you want to duplicate.
  2. Call .clone() or .clone(true) / .clone(true, true) as needed.
  3. Optionally change attributes (especially id) on the clone.
  4. Insert with .appendTo(), .prependTo(), .insertAfter(), etc.
PieceRequired?Role
Matched setYesElement(s) to deep-copy
withDataAndEventsOptionalCopy events + .data() (default false)
deepWithDataAndEventsOptionalSame for descendants (1.5+; defaults to first arg)
Return—New jQuery set of cloned elements

Pseudocode

Pseudocode
for each matched element el:
    copy = deep_copy(el and all descendants)

    if withDataAndEvents:
        copy events and .data() on el
        // note: object/array data values stay shared

    if deepWithDataAndEvents:
        copy events and .data() on descendants too

    add copy to result set

return result set   // original DOM unchanged until you insert

Cheat Sheet

Keep these facts handy while duplicating nodes.

TopicDetail
Syntax.clone([withDataAndEvents][, deepWithDataAndEvents])
Since1.0; data+events 1.4; deep flag 1.5
DefaultStructure only — no events/data
vs moveClone keeps original; plain append moves
IDsCopied — make unique after clone
Form stateinput kept; textarea/select often not
Data objectsShared references unless you deep-copy

Live Preview

Clone #card into #tray — or move it without cloning.

Browser demo of .clone() vs move — same idea as the examples below.

Hello
Tray:
Result
$("#card").clone().appendTo("#tray")
→ original stays; copy appears in tray

jQuery Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

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.
  4. Original. The source <b> elements remain where they were.

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.
  4. Chain. Insertion methods act on the clone set, not the original.

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.
  4. Children. Use .clone(true, true) if nested handlers must copy too.

Example 4 — Fix Duplicate id After Clone

Change the clone’s id before putting it in the document.

jQuery
$("#card")
  .clone()
  .attr("id", "card-2")
  .appendTo("#tray");
Try It Yourself

How It Works

  1. Clone. Attributes — including id — are copied.
  2. Rename. .attr("id", "card-2") makes the copy unique.
  3. Insert. Append into the tray only after the id is fixed.
  4. Tip. Prefer classes when building reusable templates.

Edge Cases & Pitfalls

Check these before relying on .clone() in production.

id

Duplicate IDs break uniqueness

Always rename cloned ids (and related for / ARIA hooks) before insert.

events

Handlers need .clone(true)

Default clones look the same but do not fire the original handlers. Pass true (and the deep flag when needed).

data

Object .data() is shared

Arrays/objects in .data() are not deep-copied. Clone them manually if originals must stay independent.

forms

Textarea / select state may be lost

Typed input values usually copy; textarea text and select choices often do not — re-apply if required.

Browser Support

.clone() has been part of jQuery since 1.0. Copying events/data arrived in 1.4; deepWithDataAndEvents arrived in 1.5 (default false again from 1.5.1).

✓ Stable · jQuery 1.0+

jQuery .clone()

Supported in all browsers that run jQuery 1.0+. Prefer a current jQuery 3.x build for modern projects.

100% jQuery core method
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
.clone() Universal

Bottom line: Safe for any project that already loads jQuery. Use .clone(true) when handlers must travel with the copy.

Performance Notes

ApproachCostBest for
.clone()Deep DOM copySmall/medium widgets
.clone(true, true)HeavierTrees with nested handlers
Build with $("<div>")Often cheaperMany identical rows from data

Cloning large subtrees repeatedly is expensive. For big lists, prefer a template string or a DocumentFragment instead of cloning a live node hundreds of times.

Key Takeaways

  • Role: deep-copy matched elements; original stays put.
  • Insert: chain .appendTo() / .insertAfter() on the clone.
  • Events: use .clone(true) (and deep flag for children).
  • IDs: rename clones before inserting into the document.

One line: .clone() duplicates nodes so you can insert copies without moving the original.

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()

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

.insertAfter() tutorial →

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