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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:02:44+00:00 2026-06-07T11:02:44+00:00

I am trying to have <li> s hide and show based on their class

  • 0

I am trying to have <li>s hide and show based on their class names (most of which are multiple classes) selected by the user using a checkbox selector for individual attributes. I have noticed however that in my implementation, it looks for the attribute, and performs the task, regardless of all of the other attribute selectors on the form. How can I adjust the code so that it shows the <li>s based on visibility selections of the individual class attributes?

Here is the fiddle.

As you can see, if you check the ‘A’ box, it hides ‘A’, ‘AB’, ‘AC’, and ‘ABC’. However the user thinks that any <li> with attributes ‘B’ and ‘C’ are visible, and ‘AB’, ‘AC’, and ‘ABC’ are hidden.

So if the user selects ‘A’ to be hidden, then the only <li> to be hidden is

‘A’

, since it is the only one with just ‘A’, and ‘B’ and ‘C’ are attributes the user wants to be visible, leaving the following visible:

‘B’, ‘C’, ‘AB’, ‘AC’, ‘BC’, “ABC’

. If the user selects ‘A’ and ‘B’ to hide, then the following would be hidden:

‘A’, ‘B’, ‘AB’

; and visible would be:

‘C’, ‘AC’, ‘BC’, and ‘ABC’

, since they have a ‘C’ class attribute.
I’m assuming I would have to make an array or something similar, and then look for any attributes within the array, and display/hide them accordingly.

  • 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-07T11:02:45+00:00Added an answer on June 7, 2026 at 11:02 am

    Here’s a way to do it with a bit less code:

    http://fiddle.jshell.net/vnjHn/1/

    $('form input').on('change', function() {
    
        var notSelectedList = $('form input:not(:checked)').map(function() {
            return '.' + $(this).attr('name');
        }).get().join(',');
    
        $('.viewing li').each(function() {
            $(this).toggle($(this).is(notSelectedList));
        });
    
    });​
    

    It works by building up a comma separated list of the classes which are not to be hidden, an then checks all the list items for any of these classes – which is a slightly easier way of doing the check I think.

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

Sidebar

Related Questions

I'm trying to hide window after its startup. I have own window-class which is
I'm trying to toggle hide/show on all divs with the same class. I have
I have a question about usability/design. I currently am using some JQuery to hide/show
I'm trying to toggle (hide/show) a table when clicking a button which is located
I am trying to figure out how to show/hide a navigation link based on
I'm trying to show some different divs based on the value a user has
Hi I have been trying to make a show/hide toggle button with jquery but
Upon submit I am trying to have quiz hide and have thanks be shown.
I have a problem trying to hide .php extension from the url I have
I have a table column I’m trying to expand and hide. jQuery seems to

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.