I have a list where I add rows with Add button using Jquery. Now I also want to remove the dynamically added rows so I created a delete button dynamically along with the rows too but that delete button is not working.
<div id="quantityTable">
<div class="row frmrw">
<div class="form-group col-md-6">
<label class="col-md-6 control-label" for="name">Quantity:</label>
<div class="col-md-6">
<input type="text" class="form-control" placeholder="Quantity" name="quantity" />
</div>
</div>
<div class="form-group col-md-6">
<div data-role="button" id="addQty" class="btn btn-success">Add Quantity</div>
</div>
the jquery that appends a similar row in the list along with a remove button
$("#addQty").click(function () {
$("#quantityTable").append("<div class=\"row frmrw\"> "+
"<div class=\"form-group col-md-6\"> "+
"<div class=\"col-md-6\">"+
"<input type=\"text\" class=\"form-control\" "+
"placeholder=\"Quantity\" name=\"quantity\" /> </div></div> "+
"<div class=\"form-group col-md-6\">"+
"<div data-role=\"button\" id=\"rmvQty\" class=\"btn btn-success\"> "+
"Remove Quantity</div> </div> </div>");
}
);
Now when I click on the remove button I need to remove that particular
row
$("#rmvQty").on("click", function () {
console.log("as");
});
Firstly the jquery for remove is not working and secondly how do I remove the row that was clicked on.
EDIT : my solution
$("#quantityTable").on("click", function (e) {
if(e.target.id == "rmvQty" ){
e.target.parentNode.parentNode.remove();
}
});