如果div中有图像,则隐藏div.但如果图像确实存在,那么我需要保持div可见.
但它不起作用.这是我的代码:
HTML:
<table id="FeatureBox">
<tbody>
<tr>
<td>
<div id="productInfoGrid">
<div id="ProductIconsTitle">
<p>PRODUCT FEATURES</p>
</div><img width="563" height="337" src="http://www.preserveshop.co.uk/images/black-jam-jar-lid-58mm.jpg" alt="http://www.preserveshop.co.uk/images/black-jam-jar-lid-58mm.jpg" style="cursor: -moz-zoom-in"><div style="clear:both;"></div>
</div>
</td>
</tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)
JQUERY:
if ($("#div#productInfoGrid:not(img)").length) {
$("#productInfoGrid").hide();
}
Run Code Online (Sandbox Code Playgroud)
JSFIDDLE:http://jsfiddle.net/wJgpr/3/
if ( !$("#productInfoGrid").has("img") ) {
$(this).hide();
}
Run Code Online (Sandbox Code Playgroud)
或者更简单
$("#productInfoGrid").not(':has("img")').hide();?
Run Code Online (Sandbox Code Playgroud)