Skip to content Skip to sidebar Skip to footer

Adding A Table Cell Into Only Cloned Table

I want to add a new TD into cloned table so it will only exist in cloned table not in original one. The reason is, I don't want users to remove original table otherwise there won't

Solution 1:

Try to .append() that required element over that clone,

$(document).ready(function () {
    $('.add-another-table').click(function (event) {
        event.preventDefault();
        var clonedTable = $(this).prev('table').clone();
        $(this).before(clonedTable.find('.remove-table').remove().end().find('tr').append('<td class="remove-table"><span>REMOVE</span></td>').end());
    });

    $('div').on('click', '.remove-table', function (event) {
        event.preventDefault();
        $(this).closest('table').remove();
    });
});

DEMO


Post a Comment for "Adding A Table Cell Into Only Cloned Table"