Problem when deleting dynamically added row from html table using jquery

I created a dynamic table that added a new row when I clicked the button. This table contains a column named Delete . Whenever a-link is deleted, the corresponding line should be deleted. But my jquery is not working.

A fragment that deletes a record from a table:

$(".delRow").click(function()
                        {
                            alert("Called");
                             $(this).parents('tr').first().remove();


                        }
                    ); 

Here is the jsfiddle LINK link

Refresh . Please note: I successfully delete this line, which is not added dynamically. Even the warning is not triggered when I click on the β€œDelete a-link” column of a line added dynamically.

+2
3

.delRow , .on .

on, jQuery , . , . , , . , .

            /*Remove Text Button*/
            $("#sample-table").on("click", ".delRow", function()
                {
                    $(this).parents("tr").remove();
                }
            ); 

http://jsfiddle.net/qRUev/2/

+4

$('.delRow').live('click', function (){
   alert("Called");
});

$(".delRow").click(function(){
   alert("Called");
});
+2

$(document).on('click', ".delRow", function()
                    {
                        alert("Called");
                         $(this).parents('tr').first().remove();


                    }
                ); 

Demo: Fiddle

+1
source

Source: https://habr.com/ru/post/1610308/


All Articles