I'm trying to remove a product from my page after clicking the delete button
if(products && products.length>0)
.products
.row
h4.col.text-center My Products
hr
each product in products
.row.prod-row
.col
| #{product.prod_name}
.col
button.editprd.btn.btn-primary(type="button" data-id=product.prod_id data-url="/b/prod/edit") Edit
button.delprd.btn.btn-primary(type="button" data-id=product.prod_id data-url="/b/prod/del") Delete
else
| You have not added any product in this category.
My JQuery looks like this
$(document).on('click', ".delprd", function(e) {
product = $(this).data("id");
$.ajax({
url: $(this).data("url"),
type: "GET",
data: { prodId: $(this).data("id") },
success: function(data, status, xhr) {
$product.remove();
},
error: function(jqXhr, textStatus, errorMessage) {}
});
});
Although the product is getting deleted after refreshing the page, I can't see it disappear right after I click the Delete button
product.prod_idvalue relate to the element in the DOM? Can it be used to select it? If so, then you just need to create a jQuery object from the selector and callremove(). If you need an example of this, please add the relevant HTML to the question. Note, HTML not pseudo code or a template.const product = $(this).data("id");and then just pass variable inurl:anddata:$productis undefinedvar row = $(this).closest("tr")then replace$product.remove()withrow.remove()