Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 658
Quamis Avatar asked Sep 03 '26 22:09

Quamis


2 Answers

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')
like image 98
nemke Avatar answered Sep 05 '26 11:09

nemke


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

duplicate = document.getElementById("originalSelector").cloneNode(true);
like image 34
David Larsen Avatar answered Sep 05 '26 11:09

David Larsen