繁体   English   中英

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

[英]check if div contains li then removing another element using jquery

如果div#FeatureIconsWrapper包含li

然后div#productInfoGrid由CSS隐藏或完全删除。

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

$("div#FeatureIconsWrapper:not(li)")({
    $("div#productInfoGrid").hide();
});

尝试这个,

现场演示

if($("div#FeatureIconsWrapper li").length == 0)
{
    $("div#FeatureIconsWrapper").hide();
}

您可以使用:has

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

演示: http : //jsfiddle.net/8T4ka/2/

请尝试以下方法:

API: http//api.jquery.com/has/

$(document).ready(function() {

       if ($("div#FeatureIconsWrappet:not(:has(li))")) { //.hide()
               $("div#productInfoGrid").hide();
        }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM