Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy Table row to another table HTML

Fiddle

I have two tables. When I click on one table row it will copy to another table, and I will change the button as my requirement. Please help me.

$(window).load(function() {
                var items = [];

                $(".addBtn").on("click", function() {
                    var newTr = $(this).closest("tr").clone();

                    var newButtonHTML = "<input type = 'button' value='Edit' onclick='Edit()' /><input type='button' value='Delete' onclick='deleteRow(this.parentNode.parentNode.rowIndex)'/>";
                    $(newButtonHTML).children("button").click(function(e) {
                    });

                    $(newTr).children("td:last").html("").html(newButtonHTML);
                    items.push(newTr);
                    newTr.appendTo($("#stopsTable"));

                });
like image 763
user3547883 Avatar asked Jul 29 '26 12:07

user3547883


1 Answers

At your example it was a wrong selector

$('#myTable.tr') 

instead of

$('#myTable tr')

Check fixed version: http://jsfiddle.net/V7wXD/7/

Best regards!

like image 147
Borza Adrian Avatar answered Aug 01 '26 02:08

Borza Adrian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!