jQuery Document Manipulation - clone() Method
Example
Clone and append a p element:
$("button").click(function(){ $("body").append($("p").clone()); });
Definition and Usage
The clone() method generates a copy of the selected element, including child nodes, text, and attributes.
Syntax
$(selector).clone(includeEvents)
Parameters | Description |
---|---|
includeEvents |
Optional. Boolean. Specifies whether to copy all event handlers of the element. By default, the clone does not contain event handlers. |
More examples
- Copy an element, including event handlers
- Use the clone() method to copy elements, including their event handlers.