Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果span包含0,Jquery将隐藏父标签_Javascript_Jquery - Fatal编程技术网

Javascript 如果span包含0,Jquery将隐藏父标签

Javascript 如果span包含0,Jquery将隐藏父标签,javascript,jquery,Javascript,Jquery,我有以下几种标签: <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"

我有以下几种标签:

<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>
但是如何隐藏父标签呢?
谢谢

首先,您在过滤器内缺少返回。没有它,你永远找不到元素。其次,您需要在树上查找标签,因此必须使用最近的

$(“.brand_counts”).filter(函数(){
return$(this).text().trim()=“0”;//您错过了此处的return
}).closest('label').hide();//选择最近的祖父母

BMW0

在调用hide之前选择父项要隐藏“标签”或“span.自定义控件标签”或“span.标签”?整个标签
$(".brand_counts").filter(function(){
           $(this).text().trim() === "0";
        }).hide();