开发者

How to Add/remove row in table in jquery when we check and uncheck the checkbox in other table?

i have one table开发者_如何学运维 where i have select the row by checking check box. I wanted to add selected checkbox rows to another table which is dynamically created when some one check checkbox.

I am waiting for you response


Something like

$("#firsttableid input:checkbox").click(function(){
    $(this).closest("tr").appendTo("#yoursecondtableid");
});

Edit

If you dont' want to move the row then you can use .clone() to the row and then append to the other table like. Also a change in the click handler to not add the row when the checkbox is unchecked. If you don't want to add a row again and again you have to take care of that too.

$("#firsttableid input:checkbox").click(function(){
    if ($ (this).is(":checked"))
    {
        $(this).closest("tr").clone().appendTo("#yoursecondtableid");
    }
});

Working Demo

Working Demo with remove


Basically as rahul suggested but a minor addition adding clone()

$('#first_table_id input:checkbox').click(function() {
    $(this).closest('tr').clone().appendTo('#second_table_id');
});

Jquery API documentation is your friend :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜