如果relatedProductsArea中没有图像,则隐藏div。
<div id="RelatedProductsArea" style="border-radius: 7px 7px 7px 7px;"><br clear="all"><div style="clear:both;"></div>
</div>
未找到图像意味着没有相关产品。
我试过的
$('#RelatedProductsArea').has('img').css('border', 'none');
这是一个示例:http://jsfiddle.net/K2Cp6/
问题:如何在jsfiddle示例中隐藏div或删除边框?
最佳答案
if($('#RelatedProductsArea img').length)) {
$('#RelatedProductsArea').hide();
}
DEMO
要么
$('#RelatedProductsArea').not(':has(img)').hide();
.not()
将过滤没有图像的div
。DEMO
要么
$('#RelatedProductsArea').has(':not(img)').css('display', 'none');
DEMO
根据编辑
要隐藏,请使用
.hide()
或.css('display','none')
并删除边框,请使用.css('border', 'none')
。如果您都想要.css({
display: 'none',
border: 'none'
})