JQuery Clone Row
$( ".element1" ).clone().appendTo( ".element2" );
Lokesh Thakur
$( ".element1" ).clone().appendTo( ".element2" );
/*
<table>
<tr>
<td>one</td>
<td><button type="button" class="js-clone-row">duplicate</button></td>
</tr>
<tr>
<td>two</td>
<td><button type="button" class="js-clone-row">duplicate</button></td>
</tr>
</table>
*/
$(function() {
/** Note: Assumes we are called from somewhere inside a <tr> */
function cloneClosestTableRow(e) {
const closestTableRow = $(e.currentTarget).closest('tr');
const clone = closestTableRow.clone(true);
const targetContainer = closestTableRow.parent();
targetContainer.append(clone)
}
$('.js-clone-row').on('click', cloneClosestTableRow)
});