English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery clone() Method

jQuery HTML/CSS Methods

The clone() method creates a deep copy of the selected element set.

Deep copy means it will copy the selected element and all its descendant elements, attributes, and text nodes.

Syntax:

$$(selector).clone(true|false)

Example

Clone all <p> elements and insert them at the end of the <body> element:

$("button").click(function(){
  $("p").clone().appendTo("body");
});
Test See‹/›

Clone all <b> elements and place them before all paragraphs:

$("button").click(function(){
  $("b").clone().prependTo("p");
});
Test See‹/›

Clone the first <p> element that contains an event handler and insert it at the end of the <body> element:

$("p").click(function(){
  $(this).animate({fontSize: "+=5px");
});
$("button").click(function(){
  $("p:first").clone(true).appendTo("body");
});
Test See‹/›

Parameter Value

ParameterDescription
trueThe specified event handler should be copied with the element
falseThe specified event handler should not be copied with the element. This is the default value

jQuery HTML/CSS Methods