1 回答
TA贡献1818条经验 获得超8个赞
首先,您缺少过滤器内的返回。没有它,您将永远找不到元素。其次,您需要将树查找到标签,因此您必须使用最接近的。
$(".brand_counts").filter(function() {
return $(this).text().trim() === "0"; // you missed return here
}).closest('label').hide(); // select the grandparent with closest
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label class="custom-control custom-checkbox mb-3">
<input type="checkbox" class="brand custom-control-input filters filter_level_100" data-filter-level="100" data-filter-type="checkbox" name="checkbox0" id="checkbox0" value="282">
<span class="custom-control-label"> BMW<span class="label label-secondary float-right brand_counts" id="brand_counts_BMW">0</span> </span>
</label>
添加回答
举报