我有div
这样:
<div class="EventsRollup">
<span class="EventsRollupTitle">Health Lecture Events</span>
<!--this is where a table would be dynamically inserted by sharepoint
based on some filter, if filter is true, a tabel will get in there,
else not-->
</div>
使用jQuery,如果没有插入div
,如何隐藏整个table
因为div
具有背景颜色而空白背景颜色显示没有table
内容?
答案 0 :(得分:3)
if ($('.EventsRollup').find('table').length === 0) {
$('.EventsRollup').hide();
}
这假设只有一个.EventsRollup
...如果还有更多,你可以使用循环......
$('.EventsRollup').each(function() {
$this = $(this);
if ($this.find('table').length === 0) {
$this.hide();
}
});
答案 1 :(得分:3)
$('.EventsRollup').not(':has(table)').hide();
或
$('.EventsRollup:not(:has(table))').hide();
答案 2 :(得分:2)
jQuery( ".EventsRollup").filter( function(){
return !this.getElementsByTagName("table").length;
}).hide();