试图根据数据属性删除div标签 [英] trying to remove div tag based on data attribute

查看:84
本文介绍了试图根据数据属性删除div标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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+'">

我想删除包含特定product_id的行容器.我知道data('i')会检索值,但我不知道从那里去哪里.

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.

推荐答案

$('.row-container').filter(function(){
    return $(this).data('i') === "product_id"
}).remove();

.data允许您设置和获取字符串(函数和对象)以外的其他变量

.data allows you to set and get other variables beside of strings (functions and objects)

您也可以使用此:

$('.row-container').filter('[data-i="product_id"]').remove();

或使用一个选择器:

$('.row-container[data-i="product_id"]').remove();

(其中"product_id"是实际值的占位符...)

(Where "product_id" is a placeholder for the real value...)

这篇关于试图根据数据属性删除div标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆