Delete dynamically-generated table row using jQuery

das kinder

the code below add and remove table row with the help of Jquery the add function works fine but the remove only work if I remove the first row

<table>
    <tr>
    <td><button type="button"  class="removebutton" title="Remove this row">X</button>
</td> 
         <td><input type="text" id="txtTitle" name="txtTitle"></td> 
         <td><input type="text" id="txtLink" name="txtLink"></td> 
    </tr>
</table>
<button id ="addbutton">Add Row</button>

and the script

 var i = 1;
$("#addbutton").click(function() {
  $("table tr:first").clone().find("input").each(function() {
    $(this).val('').attr({
      'id': function(_, id) {return id + i },
      'name': function(_, name) { return name + i },
      'value': ''               
    });
  }).end().appendTo("table");
  i++;
});

$('button.removebutton').on('click',function() {
    alert("aa");
  $(this).closest( 'tr').remove();
  return false;
});

can anyone give me the explanation why I can only remove the first row ? thank so much

isherwood

You need to use event delegation because those buttons don't exist on load:

http://jsfiddle.net/isherwood/Z7fG7/1/

 $(document).on('click', 'button.removebutton', function () { // <-- changes
     alert("aa");
     $(this).closest('tr').remove();
     return false;
 });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

delete table row dynamically using jQuery in asp.net mvc

From Dev

To delete a row dynamically from a table using javascript

From Dev

Add/Delete row dynamically to/from jquery table using angularjs not working properly

From Dev

Append button to a table row dynamically using jquery

From Dev

Change a table row dynamically using JQuery/Javascrpit

From Dev

Appending Row to PHP generated table row using Jquery

From Dev

unable to delete row from table using jquery?

From Dev

How to delete a row in a table using jQuery?

From Dev

unable to delete row from table using jquery?

From Dev

delete any table row using jQuery

From Dev

Delete a dynamically added table row

From Dev

Delete a dynamically created table row

From Dev

Change dynamically generated table row background color

From Dev

Change dynamically generated table row background color

From Dev

Removing dynamically added row from a table using jquery

From Dev

How to add dynamically a row to a table in the ejs using jquery?

From Dev

Form Tag is misplaced on adding dynamically using jquery in a table as a row

From Dev

Removing a table row dynamically using jquery doesn't work

From Dev

remove a row from dynamically created table using jquery

From Dev

How to add dynamically a row to a table in the ejs using jquery?

From Dev

Add id to dynamically created row using bootstrap table in jquery

From Dev

Can't properly delete rows from a dynamically generated table using a button

From Dev

Dynamically delete the table by using parameter

From Dev

How to identify dynamically generated image id's in a table row by using nightwatch JS

From Dev

Show and hide dynamically generated table elements with jQuery

From Dev

How to add class to dynamically generated table in jquery?

From Dev

Create Jquery datepicker in dynamically generated table rows

From Dev

How to add class to dynamically generated table in jquery?

From Dev

Clearing dynamically generated table with data in jquery

Related Related

  1. 1

    delete table row dynamically using jQuery in asp.net mvc

  2. 2

    To delete a row dynamically from a table using javascript

  3. 3

    Add/Delete row dynamically to/from jquery table using angularjs not working properly

  4. 4

    Append button to a table row dynamically using jquery

  5. 5

    Change a table row dynamically using JQuery/Javascrpit

  6. 6

    Appending Row to PHP generated table row using Jquery

  7. 7

    unable to delete row from table using jquery?

  8. 8

    How to delete a row in a table using jQuery?

  9. 9

    unable to delete row from table using jquery?

  10. 10

    delete any table row using jQuery

  11. 11

    Delete a dynamically added table row

  12. 12

    Delete a dynamically created table row

  13. 13

    Change dynamically generated table row background color

  14. 14

    Change dynamically generated table row background color

  15. 15

    Removing dynamically added row from a table using jquery

  16. 16

    How to add dynamically a row to a table in the ejs using jquery?

  17. 17

    Form Tag is misplaced on adding dynamically using jquery in a table as a row

  18. 18

    Removing a table row dynamically using jquery doesn't work

  19. 19

    remove a row from dynamically created table using jquery

  20. 20

    How to add dynamically a row to a table in the ejs using jquery?

  21. 21

    Add id to dynamically created row using bootstrap table in jquery

  22. 22

    Can't properly delete rows from a dynamically generated table using a button

  23. 23

    Dynamically delete the table by using parameter

  24. 24

    How to identify dynamically generated image id's in a table row by using nightwatch JS

  25. 25

    Show and hide dynamically generated table elements with jQuery

  26. 26

    How to add class to dynamically generated table in jquery?

  27. 27

    Create Jquery datepicker in dynamically generated table rows

  28. 28

    How to add class to dynamically generated table in jquery?

  29. 29

    Clearing dynamically generated table with data in jquery

HotTag

Archive