2011-11-30 73 views
1

我想隱藏哲學泡沫div,它看起來像一個講話泡泡,但如果內部div是空的,泡泡將會是一個需要隱藏的空洞的講話泡泡。我如何使用jQuery來做到這一點?如果內部div爲空,如何隱藏父div?

<div class="philosophy-bubble"> 
    <div id="ctl00_PlaceHolderMain_ctl00_ctl15__ControlWrapper_RichHtmlField" class="ms-rtestate-field" style="display:inline" aria-labelledby="ctl00_PlaceHolderMain_ctl00_ctl15_label"> 
    <DIV id="ctl00_PlaceHolderMain_ctl00_ctl15_RichHtmlField_displayContent" class="ms-rtestate-write" EmptyPanelId="ctl00_PlaceHolderMain_ctl00_ctl15_RichHtmlField_EmptyHtmlPanel" style="display:;"> 
    PROVIDING CARING AND KNOWLEDGABLE MEDICAL CARE TO PATIENTS 
    </DIV> 
    </div> 
</div> 

回答

1
if(!($('.philosophy-bubble').html())) $('.philosophy-bubble').hide(); 
1

使用.text()$.trim分析每個div的非HTML內容:

$('div.philosophy-bubble').each(function() { 
    if ($.trim($(this).text())==='') { 
     $(this).hide(); // or .remove() 
    } 
}); 
2

這應做到爲每一個這樣的DIV頁面上:

$('.philosophy-bubble').each(function() { 
    var c = $(this).children().children(); // find the inner div 
    if (c.html().length == 0) {   // check its content's length 
     $(this).hide(); 
    } 
});