Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4054770
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:37:03+00:00 2026-05-20T14:37:03+00:00

I have a set of nested ul’s that look like this: <ul id=educationList> <li

  • 0

I have a set of nested ul’s that look like this:

<ul id="educationList">
    <li class="category"><p>Media production</p>
       <ul>
          <li class="education" style="display: block;">
             <a href="#">Real time 3D animation</a>
          </li>
          <li class="education" style="display: block;">
             <a href="#">Filming with Steadicam</a>
          </li>
          <li class="education" style="display: block;">
             <a href="#">Sound Effects</a>
          </li>
       </ul>
    </li>
</ul>

The top ul (educationList) holds a list of categories and each category has a sub list (ul) with the educations that sort under this category. A classic nested list structure. In the sample code above I have just one category – in the real code there are a lot of categories.

I have a jQuery filtering function that shows/hides li-elements that have the class “education” (sub list elements). Sometimes this filtering function hides all sub list elements, so the HTML looks like this:

<ul id="educationList">
    <li class="category"><p>Media production</p>
       <ul>
          <li class="education" style="display: none;">
             <a href="#">Real time 3D animation</a>
          </li>
          <li class="education" style="display: none;">
             <a href="#">Filming with Steadicam</a>
          </li>
          <li class="education" style="display: none;">
             <a href="#">Sound Effects</a>
          </li>
       </ul>
    </li>
</ul>

The difference is that all sub list elements now all have the inline style display: none. All of a sudden I have no real use for the parent li with the class “category” since there are no educations under this category.

Now I’m looking for a smart way to find all category list items that have no visible child education list items and simply hide the category list item. I will have to run this function every time that I do any filtering because the filtering will affect the child education list items – some that where visible will be hidden and some that where hidden will become visible again.

Also – I will have a lot of elements so it’s an advantage if the code is not too resource hungry. Still, this is not the time to be picky. Any solution will do and I’ll have to work on optimizing later.

Thanks in advance!
/Thomas Kahn

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:37:04+00:00Added an answer on May 20, 2026 at 2:37 pm

    This is the simple and convenient jQuery solution that doesn’t completely ignore resource usage:

    $('li.category').each(function() {
      var $li = $(this);
      if(!$li.find('li:visible').length) {
        $li.hide();
      }
    });
    

    If you need performance optimization, you could do this instead, which doesn’t have the overhead of the .each:

    var categories = $('li.category');
    for(var i=0,category;category = categories.eq(i);i++) {
      if(!category.find('li:visible').length) {
        category.hide();
      }
    }
    

    EDIT: fixed bug in optimized version

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to have the nested containers inherit that property, but when I set
In Rails 3 edge, I have set up two nested resources like this: config/routes.rb
I have an application that uses a nested set model class to organise my
I have a data set that looks like this: [ { Size : Small,
I have routes set up that look like: match '/things/:thing_id' => descriptions#index, :as =>
I have a set of nested elements like such. <div id=master> <span id=num-1 class=num></span>
Is it possible to have nested set capabilities in this somewhat custom setup? Consider
I have set a background on the data-role=page element like so <div data-role=page style=background:
I have a set of nested queries with express/mongoose, pretty much like so: app.get(...,
I have a set of nested yaml lists with something like the following: title:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.