2012-07-06 53 views

回答

4

您可以使用:has

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

DEMO:http://jsfiddle.net/8T4ka/2/

+0

什麼是':HAS'? – 2012-07-06 10:25:07

+0

@ Super1:':not(:has())':P。 – Matt 2012-07-06 10:26:06

+0

@Matt我想過,但最後轉移到簡單的'長度'檢查。它可能會更快。 – VisioN 2012-07-06 10:29:12

4

試試這個,

Live Demo

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

'this'不會有什麼有用的。 – Matt 2012-07-06 10:22:33

+0

這裏是例子,不工作:s http://jsfiddle.net/8T4ka/ – 2012-07-06 10:23:18

+0

感謝super1,我已更正並更新演示。 – Adil 2012-07-06 10:29:06

2

請試試這個:

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

$(document).ready(function() { 

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

哇,永遠不知道'有()' – Matt 2012-07-06 10:23:06