Restore Multiple Detached Elements in JQuery

后端 未结 3 1880
逝去的感伤
逝去的感伤 2021-01-21 18:54

I have a link inside of a table that, when clicked, removes the entire parent tr. I am using detach() for the purposes of restoring that item later ba

相关标签:
3条回答
  • 2021-01-21 19:35

    you should use an array to store all the dettached items: http://jsfiddle.net/nErDy/1/

    0 讨论(0)
  • 2021-01-21 19:38

    Why not use an array?

    var deleted = [];
    //Allow people to delete rows
    $('a.delete').click(function() {
        deleted.push($(this).parent().parent().detach());
    });
    
    //Restore all
    $('a.restore').click(function() {
        $.each(deleted, function(i, v) {
            $('#teams').append(v);
        });
    });​
    

    http://jsfiddle.net/wirey00/nErDy/2/

    0 讨论(0)
  • 2021-01-21 19:43

    What everyone else said, use an array. Also, move the css for odd rows into an actual css, so it respects the deleted rows.

    #teams tr:nth-child(even) td { background-color : #cecece }​
    

    http://jsfiddle.net/44Qab/

    0 讨论(0)
提交回复
热议问题