试图根据数据属性删除div标签
我想删除包含特定product_id的行容器。 我知道数据(’i’)检索值,但我不知道从那里去哪里。
$('.row-container').filter(function(){ return $(this).data('i') === "product_id" }).remove();
.data
允许您设置和获取字符串(函数和对象)旁边的其他变量
你也可以用这个:
$('.row-container').filter('[data-i="product_id"]').remove();
或者使用一个选择器:
$('.row-container[data-i="product_id"]').remove();
(其中"product_id"
是实际值的占位符…)
你可以使用filter()
:
var $div = $(".row-container").filter(function() { return $(this).data("i") == value; // where value == product id to find }); $div.remove();
jQuery中有一个属性选择器 ,您可以使用它来查找您正在查找的元素。
$('div.row-container[data-i=""]');