Delete Row HTML

I have created a Dynamic HTML table where the user can add/delete rows if they want to. There will be 2 rows to complete at one time. I want to delete the row but for my coding I only able to delete the first row, the second row cannot delete. Anyone have idea on how to delete the row?

$(document).ready(function () {
   $('#addrow').click(function () {
       addItem();
   });
   $(document).on('click', '.delete-row', function () {
       $(this).parents('.item-row').remove();
   });
});
    
function addItem() {
    var itemRow =
        '<tr class="item-row">' +
        '<td><a id="delete" href="javascript:;" title="Remove row">Delete</a></td>' +
        '<td><textarea class="form-control" id="desc" rows="1"></textarea></td>' +
        '<td><input class="form-control tx-right" type="text" id="qty" onkeyup="calc()" value="0"></td>' +
        '<td><input class="form-control tx-right" type="text" id="unitprice" value="0"></td>' +
        '<td><input class="form-control tx-right" type="text" id="amount" disabled></td>' +
        '</tr>'+
    '<tr class="item-row">' +
        '<td></td>' +
        '<td colspan="2"></td>' +
        '<td class="tx-right">Tax:</td>' +
            '<td><select class="form-control select2 input-sm" id="ddlTax">' + "<% =sTaxDDL %>" + '</select></td>' +
            '<td><input class="form-control tx-right" type="text" id="amounttax"></td>' 
    '</tr>';
}
<script
  src="https://code.jquery.com/jquery-3.5.1.min.js"
  integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
  crossorigin="anonymous"></script>
  
 <table>
      <thead>
        <tr>
          <th class="wd-5p">Action</th>
          <th class="wd-25p">Description</th>
          <th class="wd-10p tx-right">Qty</th>
          <th class="wd-10p tx-right">Unit Price</th>
          <th class="wd-15p tx-right">Amount</th>
        </tr>
      </thead>
      <tbody class="items_table">
        <tr class="item-row">
          <td><a id="delete" href="javascript:;" title="Remove row">Delete</a></td>
          <td><textarea class="form-control row-desc" id="desc" rows="1"></textarea></td>
          <td><input class="form-control tx-right row-qty" type="text" id="qty" onkeyup="calc()" value="0"></td>
          <td><input class="form-control tx-right row-unitprice" type="text" id="unitprice" value="0"></td>
          <td><input class="form-control tx-right row-amount" type="text" id="amount" disabled></td>
        </tr>
        <tr class="item-row">
          <td></td>
          <td colspan="2"></td>
          <td class="tx-right">Tax:</td>
          <td><input class="form-control tx-right" type="text" id="amounttax"></td>
        </tr>
        <tr id="hiderow">
          <td colspan="5" class="tx-center tx-15"><b><a id="addrow" href="javascript:;" title="Add a row"><i class="fe fe-plus-circle"></i>Add an Item</a></b></td>
        </tr>
      </tbody>
</table>
<!-- End Row -->



Read more here: https://stackoverflow.com/questions/66327255/delete-row-html

Content Attribution

This content was originally published by qq games at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: