0

I want to remove the current row of the table by clicking the button using jquery i have tried this , please help me.

<script>
    $(document).ready(function () {
        $("#medbtn").click(function () {
            var medicinelist = $("#medList").val();
            var selecttype = $("#TypeList").val();
            var qtyInput = $("#qty").val();
            var text = $("#medList").text();
            var data = '<tr> <td>' + text + ' </td> <td>' + selecttype + '</td> <td>' + qtyInput + '</td> <td><input type="button" value="X" id="remove"/></td> <input type="hidden" value=' + medicinelist + '/> </tr>';
            $('#listMedicine').append(data);

   i have tried this here, but not remove the row please help me thanks
            $("#remove").click(function () {
                $('data').remove();
            })
        });


            });
</script>

1 Answers1

0

You should be doing:

$("#listMedicine").on("click", ".remove", function () {
   $('data').remove();
});

Because #remove is dynamically created and DOM would not attach the click handler to it.. Also use class .remove as id can not repeat.

void
  • 33,471
  • 8
  • 45
  • 91