Greetings to all. There is a html of approximately the following structure:

<div class="title"></div> <div class="block"> <div class="item"></div> <div class="item"></div> </div> <div class="title"></div> <div class="block"> <div class="item" style="display: none"></div> <div class="item" style="display: none"></div> <div class="item" style="display: none"></div> <div class="item"></div> </div> <div class="title"></div> <div class="block"> <div class="item" style="display: none"></div> <div class="item" style="display: none"></div> </div> 

Tell me how to make the blocks of the "title" class also display: none, if all the item is inside .block display: none (as if empty), and if at least one is visible, do not touch?

I tried using the .each () function to bypass .block, but inside .each () still does not work for .item.

    1 answer 1

    Is it possible to frustrate and pack everything into one design?
    Hmm .. In general, I thought ... And something is not better than anything ...

     $(".title").hide().next().children(":visible").parent().prev().show() 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="title">A</div> <div class="block"> <div class="item"></div> <div class="item"></div> </div> <div class="title">B</div> <div class="block"> <div class="item" style="display: none"></div> <div class="item" style="display: none"></div> <div class="item" style="display: none"></div> <div class="item"></div> </div> <div class="title">C</div> <div class="block"> <div class="item" style="display: none"></div> <div class="item" style="display: none"></div> </div> 

    • It works))) I can only laugh at myself and at the time spent)) Thank you! - Melst
    • In general, it is customary to accept the best answer by clicking on the check mark to the left of it. Although, in this case, you can wait - suddenly someone will offer something more correct. The label of an accepted answer can always be rearranged to another, but questions without accepted answers usually receive more attention. At first I thought that this answer was not very good, but then I realized something, that nothing was better than something. - Qwertiy
    • Clicked)) Thanks again. - Melst