treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Hiding an Empty Div with jQuery

  • Hi all - I have been having such a hard time trying to hide a div that is empty with jQuery. Any Ideas?

    $(document).ready(function() {
    if($(".itemBubble").html() == ""){
    $(".itemBubble").addClass("visuallyhidden");
    }
    });


    <div class="itemTextContainer">

    <div class="itemTextWrap">

    <h3 class="itemText"><a href="http://www.st.com/Weather-Stripping-Gaskets">Weather Stripping / Gaskets</a></h3>

    </div>

    </div>

    </div> <div class="itemBubble itemProductSpacer noMargin">

    <a href="http://www.st.com/Assorted-Products&quot; title="Assorted Products"><img src="/set-dur/duracoexpress/img/fullSizedImage/assorTape.jpg" alt="Assorted Products" class="borderBottom"></a>



    <div class="itemTextContainer">

    <div class="itemTextWrap">

    <h3 class="itemText"><a href="http://www.st.com/Assorted-Products">Assorted Products</a></h3>

    </div>

    </div>

    </div>



    <div class="itemBubble itemProductSpacer">



    </div>



    <div class="itemBubble itemProductSpacer">



    </div>
  • well the problem is that you have multiple divs with class .itemBubble i guess.
    you have to use something like each. dont know if theres a better way, im no expert.. but maybe it helps:
    http://jsfiddle.net/wHpkw/4/
  • Thanks! I figured out that it wasn't working because I had some weird spacing going on.