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 9116083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:35:10+00:00 2026-06-17T04:35:10+00:00

I am trying to figure out how to traverse into elements depending on a

  • 0

I am trying to figure out how to traverse into elements depending on a class name and perform some action if it has this class or do something else if it doesn’t.

Please see my code so far:

<script type="text/javascript">
jQuery(document).ready(function($) {
     var container = $('.container');

     container.each(function() {
          // if all list item has class of hidden then hide parent container
          container.hide();

          // if not all list item has class of hidden then show parent container
          container.show();
     });
});
</script>

<div class="container container1">
     <ul>
          <li class="item">item 1</li>
          <li class="item hidden">item 2</li>
          <li class="item">item 3</li>
          <li class="item">item 4</li>
     </ul>
</div>

<div class="container container2">
     <ul>
          <li class="item hidden">item 1</li>
          <li class="item hidden">item 2</li>
          <li class="item hidden">item 3</li>
          <li class="item hidden">item 4</li>
     </ul>
</div>

From the code above the desired result is container2 should be completely hidden because all the list item within has a class of “hidden”. While container1 shows because not all list items have the class “hidden”.

As you can see, I got as far as using the “each” function to iterate through the containers but I am stuck on how to implement where it will check each list item for the specific class. My thought would be to perform another each function within it? But not sure…

Thanks for looking.

  • 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-06-17T04:35:12+00:00Added an answer on June 17, 2026 at 4:35 am

    You can further select with container as context and hide the container, when the number of hidden items is equal to all list items. Show otherwise.

    $('.container').each(function() {
      var li1 = $('li', $(this)).length;
      var li2 = $('li.hidden', $(this)).length;
      if (li1 == li2)
        $(this).hide();
      else
        $(this).show();
    });
    

    See JSFiddle for testing.

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

Sidebar

Related Questions

Trying to figure out how to hook into some web part verb events; specifically,
Trying to figure out how I can do this properly. The print_r looks like
trying to figure out why this is happening - I have an input text
I have a Btree and I'm trying to figure out how traverse it so
I'm trying to figure out how to traverse a generic list of items that
Trying to figure out a way to throw out attributes in this data that
Trying to figure out why my list() class pointers are being overwritten with the
I'm trying to figure out how to traverse a 2.5D grid in an efficient
I'm trying figure out if this is possible. Basically, I need to create an
Trying to figure out why this swf which is loaded via javascript which is

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.