remove row from the tables in jquery ajax

I have two tables and I want to remove one specific row which means that from #tr in #table2 or #tr in #table1 with jquery Ajax after success

please help me

Thank you for your help.

I added also jquery code...

<table id="table1">
<tbody>
<tr id="tr1"><td>row1</td></tr>
<tr id="tr2"><td>row2</td></tr>
<tr id="tr3"><td>row3</td></tr>
<tr id="tr14"><td>row4</td></tr>
</tbody>
</table>

<table id="table2">
<tbody>
<tr id="tr1"><td>row1</td></tr>
<tr id="tr2"><td>row2</td></tr>
<tr id="tr3"><td>row3</td></tr>
<tr id="tr4"><td>row4</td></tr>
</tbody>
</table>

   $(document).off("click", ".removeUserType").on("click", ".removeUserType", function () {
        var userTypeId = $(this).closest("tr").attr("id");
        var currentElement = $(this);
        var menuId = "<?php echo $menuId; ?>";
        var todoStatus = "remove";
        
        $.ajax({
            metod: "POST",
            url: "page.php",
            data: {todoStatus: 'remove', userTypeId: userTypeId, menuId: menuId, removeTr: removeTr},
            success: function (response) {
                console.log(response);
                notification("success");

                currentElement.closest("tr").remove(); 


            },
            error: function (err) {
                //alert("Error");                    
                notification("error");
            }

        });


    });

I added my js code also.

Answers 1

  •             $(document).off("click", ".removeUserType").on("click", ".removeUserType", function () {
            var userTypeId = $(this).closest("tr").attr("id");
            var menuId = "<?php echo $menuId; ?>";
            var todoStatus = "remove";
            $("#" + userTypeId).remove(); // THIS IS WORKING 
    
            $.ajax({
                metod: "POST",
                url: "page.php",
                data: {todoStatus: 'remove', userTypeId: userTypeId, menuId: menuId, removeTr: removeTr},
                success: function (response) {
                    console.log(response);
                    notification("success");
                    
                    $("#" + userTypeId).remove(); // THIS IS NOT WORKING 
    
    
                },
                error: function (err) {
                    //alert("Error");                    
                    notification("error");
                }
    
            });

    removeTr.remove(); is working outside of the ajax block but not working inside the ajax block


Related Articles