Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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
检查div是否包含li,然后使用jquery删除另一个元素_Jquery - Fatal编程技术网

检查div是否包含li,然后使用jquery删除另一个元素

检查div是否包含li,然后使用jquery删除另一个元素,jquery,Jquery,如果div#featureiconswapper不包含li 然后div#productInfoGrid被css隐藏或完全删除 我尝试过(这是正确的吗?): 试试这个 if($("div#FeatureIconsWrapper li").length == 0) { $("div#FeatureIconsWrapper").hide(); } 请试试这个: API: 您可以使用: 演示:这个不会有任何用处。哇,从来都不知道has()与有什么相反:has?@Matt我想了想,但最后转到了

如果
div#featureiconswapper
不包含
li

然后
div#productInfoGrid
被css隐藏或完全删除

我尝试过(这是正确的吗?):

试试这个

if($("div#FeatureIconsWrapper li").length == 0)
{
    $("div#FeatureIconsWrapper").hide();
}
请试试这个:

API:

您可以使用:


演示:

这个
不会有任何用处。哇,从来都不知道
has()
有什么相反:has
?@Matt我想了想,但最后转到了简单的
长度
检查。它可能更快。
if($("div#FeatureIconsWrapper li").length == 0)
{
    $("div#FeatureIconsWrapper").hide();
}
$(document).ready(function() {

       if ($("div#FeatureIconsWrappet:not(:has(li))")) { //.hide()
               $("div#productInfoGrid").hide();
        }
});
if (!$("#FeatureIconsWrapper:has(li)").length) {
    $("#productInfoGrid").hide();   // or remove()
}​