如果内容丢失,如何隐藏DIV [英] How to hide a DIV if content are missing

查看:96
本文介绍了如果内容丢失,如何隐藏DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



源代码的屏幕截图:



我有一些DIV内容是由Ektron CMS自动生成的。



输出:





如果DIV类 justPad ,每个父DIV( {letter} Serv )为空c>至少不会出现一次。所以根据屏幕截图,A和C有内容,但B和D没有。



如何隐藏 {letter} Serv DIV如果里面没有内容?

我可以申请以下类:

  .hideDiv {
display:none;

$ / code>

示例代码:

 < div id =nServclass =serviceHolder hidOverflow percPadBottom letterCode> 
< h2 class =defaultBlue percPadBottom> N< / h2>
< span id =ctl00_BodyPlaceHolder_Collection15>
< a href =#ViewEditorsMenudata-ektron-editorsmenu-id =EktronEditorsMenu3c275505-4a2c-4384-bf36-081bc3e69279onclick =return false; class =EktronEditorsMenuMarker>< img src =/ WorkArea / images / application / pin_grey.gifalt =Editor's Menutitle =Editor's Menu/>< / a>
< ul id =EktronEditorsMenu3c275505-4a2c-4384-bf36-081bc3e69279class =EktronEditorsMenustyle =display:none;>
{CONTENTS}
< / ul>
< div class =justPad>< a class =defaultLinkshref =link>肾脏科< / a>< / div>
< div class =justPad>< a class =defaultLinkshref =link>神经病学< / a>< / div>
< div class =justPad>< a class =defaultLinkshref =link>营养< / a>< / div>
< / span>
< / div>

< div id =bServclass =serviceHolder hidOverflow percPadBottom letterCode>
< h2 class =defaultBlue percPadBottom> B< / h2>
< span id =ctl00_BodyPlaceHolder_Collection15>
< a href =#ViewEditorsMenudata-ektron-editorsmenu-id =EktronEditorsMenu3c275505-4a2c-4384-bf36-081bc3e69279onclick =return false; class =EktronEditorsMenuMarker>< img src =/ WorkArea / images / application / pin_grey.gifalt =Editor's Menutitle =Editor's Menu/>< / a>
< ul id =EktronEditorsMenu3c275505-4a2c-4384-bf36-081bc3e69279class =EktronEditorsMenustyle =display:none;>
{CONTENTS}
< / ul>
< / span>
< / div>


解决方案

这会找到所有空的Div并隐藏它们。

  $('div.serviceHolder:not(:has(div.justPad))')。hide()


I have some DIV which has contents that are auto generated by Ektron CMS.

Screenshot of the source:

Output:

Each parent DIV ({letter}Serv) is empty if the DIV class justPad doesn't appear at least once. So based on the screenshots, A and C has content but B and D doesn't.

How can I hide the {letter}Serv DIV if there is no content inside it?

I have the following class that I can apply:

.hideDiv {
     display: none;
}

Sample code:

<div id="nServ" class="serviceHolder hidOverflow percPadBottom letterCode">
    <h2 class="defaultBlue percPadBottom">N</h2>
        <span id="ctl00_BodyPlaceHolder_Collection15">
        <a href="#ViewEditorsMenu" data-ektron-editorsmenu-id="EktronEditorsMenu3c275505-4a2c-4384-bf36-081bc3e69279" onclick="return false;" class="EktronEditorsMenuMarker"><img src="/WorkArea/images/application/pin_grey.gif" alt="Editor's Menu" title="Editor's Menu" /></a>
        <ul id="EktronEditorsMenu3c275505-4a2c-4384-bf36-081bc3e69279" class="EktronEditorsMenu" style="display:none;">
            {CONTENTS}
        </ul>
        <div class="justPad"><a class="defaultLinks" href="link">Nephrology</a></div>
        <div class="justPad"><a class="defaultLinks" href="link">Neurology</a></div>
        <div class="justPad"><a class="defaultLinks" href="link">Nutrition</a></div>
    </span>
</div>

<div id="bServ" class="serviceHolder hidOverflow percPadBottom letterCode">
    <h2 class="defaultBlue percPadBottom">B</h2>
        <span id="ctl00_BodyPlaceHolder_Collection15">
        <a href="#ViewEditorsMenu" data-ektron-editorsmenu-id="EktronEditorsMenu3c275505-4a2c-4384-bf36-081bc3e69279" onclick="return false;" class="EktronEditorsMenuMarker"><img src="/WorkArea/images/application/pin_grey.gif" alt="Editor's Menu" title="Editor's Menu" /></a>
        <ul id="EktronEditorsMenu3c275505-4a2c-4384-bf36-081bc3e69279" class="EktronEditorsMenu" style="display:none;">
            {CONTENTS}
        </ul>
    </span>
</div>

解决方案

This should find all of your empty Divs and hide them.

$('div.serviceHolder:not(:has(div.justPad))').hide()

这篇关于如果内容丢失,如何隐藏DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆