.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+)
Call
What 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
Parameter
Description
Step 1
Select the element(s) you want to duplicate.
Step 2
Call .clone() or .clone(true) / .clone(true, true) as needed.
Step 3
Optionally change attributes (especially id) on the clone.
Return Value
Return Value
Description
Boolean
Often true or false depending on the match or state.
jQuery object
Most 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.
Cloned button still fires "clicked"
.clone() alone would not keep the handler
How It Works
Bind. A click handler is attached to #btn.
clone(true). Copies the element plus events and .data().
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.