jquery delete table row

后端 未结 5 1560
后悔当初
后悔当初 2021-01-31 18:57

I have a table

5条回答
  •  长情又很酷
    2021-01-31 19:23

    The row is deleted but as clicking makes you follow the link, it's immediately restored when the page is refreshed.

    Add return false; or event.preventDefault(); at the end of the callback to prevent the default behavior :

    $(document).ready(function() {
        $("#favoriteFoodTable .deleteLink").on("click",function() {
            var tr = $(this).closest('tr');
            tr.css("background-color","#FF3700");
            tr.fadeOut(400, function(){
                tr.remove();
            });
            return false;
        });
    });
    

    Demonstration

    Note that I used closest for a more reliable code : if another element comes in between, the tr will still be found.

提交回复
热议问题
Food Name: Restaurant Name: