Search code examples
javascriptjqueryhtmlcssektron

How to hide a DIV if content are missing


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

Screenshot of the source:

enter image description here

Output:

enter image description here

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>

Solution

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

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