<div class="row-container" data-i="'+data[i].product_id+'">
<div class="row-container" data-i="'+data[i].product_id+'">
<div class="row-container" data-i="'+data[i].product_id+'">
<div class="row-container" data-i="'+data[i].product_id+'">
I want to delete the row-container that contains a particular product_id. I know data('i') retrieves the value, but I dont know where to go from there.
An <div> element can have any number of data-* attributes, each with their own name. Using data-* attributes reduces the need for requests to the server.
Make use of the removeAttribute() method to delete the given data attribute: el. removeAttribute('data-foo'); Apart from setting, getting, and erasing data values, all three methods are also used for manipulating other element attributes.
To remove elements and content, there are mainly two jQuery methods: remove() - Removes the selected element (and its child elements) empty() - Removes the child elements from the selected element.
$('.row-container').filter(function(){
return $(this).data('i') === "product_id"
}).remove();
.data
allows you to set and get other variables beside of strings (functions and objects)
You can also use this:
$('.row-container').filter('[data-i="product_id"]').remove();
Or with one selector:
$('.row-container[data-i="product_id"]').remove();
(Where "product_id"
is a placeholder for the real value...)
You can use filter()
:
var $div = $(".row-container").filter(function() {
return $(this).data("i") == value; // where value == product id to find
});
$div.remove();
There's an attribute selector in jQuery that you could use to find the element that you're looking for.
$('div.row-container[data-i="<value>"]');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With