Quamis
Quamis

Reputation: 11077

duplicate html element with jquery

anyone knows of any jquery plugin that handles duplication of some random html elements? I'm looking for a way to dynamically add identical rows to a form. I know its not hard to make, but i don't really want to reinvent the wheel here.

Upvotes: 2

Views: 3236

Answers (3)

David Larsen
David Larsen

Reputation: 51

For a native javascript solution, you can use .cloneNode(true)

duplicate = document.getElementById("originalSelector").cloneNode(true);

Upvotes: 4

nemke
nemke

Reputation: 2458

From jQuery API
The .clone() method, when used in conjunction with one of the insertion methods, is a convenient way to duplicate elements on a page.

$('originalSelector').clone().appendTo('selectorToPlaceClone')

Upvotes: 5

Gabriele Petrioli
Gabriele Petrioli

Reputation: 195982

Use the native clone method ..

$('row_selector_here').clone().appendTo('your_form_selector_here');

Upvotes: 0

Related Questions