1

Below code works properly until I insert new row by jQuery. 'delete' button doesn't work in my new row.

$(".delete").on("click", function() {
  $(this).closest('tr').remove();
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="table table-striped">
  <tbody>
    <tr>
      <td> <input type="text" /></td>
      <td>
        <a href="#" class="delete btn btn-danger btn-xs" type="button">
          <i class="fa fa-trash"></i>
        </a>
      </td>
    </tr>
  </tbody>
</table>
Umutambyi Gad
  • 4,082
  • 3
  • 18
  • 39
Elham Dabiri
  • 435
  • 2
  • 9

1 Answers1

1

If you add new row dynamicly, you have to bind like this;

$(document).on("click",".delete", function() {...

Cause you need bind dynamic created element.

Bunyomayn
  • 34
  • 4