English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
$$(selector).clone(true|false)
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 | Description |
---|---|
true | The specified event handler should be copied with the element |
false | The specified event handler should not be copied with the element. This is the default value |