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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:31:48+00:00 2026-05-31T22:31:48+00:00

I.ve been working all night to get this function to work, but i’m too

  • 0

I.ve been working all night to get this function to work, but i’m too much a noob i think 🙂

I’ve got a list of checkboxes and a list of div’s with corresponding class/id names.

I’d like to have all div’s showed on page load and when a user selects one or multiple checkboxes hide the ones not selected.

Anyone can help me out here??

So far I’ve got the following script :

$('.brand').change(function() {
        $('li.merk').not('li#m_' + $(this).attr('id') + '').toggle();

});change();

<input type="checkbox" class="brand" id="Gazelle" />
<input type="checkbox" class="brand" id="Batavus" />
<input type="checkbox" class="brand" id="Trek" />
<input type="checkbox" class="brand" id="KogaMiyata" />


<li class="merk" id="m_Gazelle" style="display:block;">
Gazelle
</li>

<li class="merk" id="m_Batavus" style="display:block;">
Batavus
</li>

<li class="merk" id="m_Trek" style="display:block;">
Trek
</li>

<li class="merk" id="m_KogaMiyata" style="display:block;">
KogaMiyata
</li>

http://jsfiddle.net/PbZRF/

SOLVED : user m90 did the trick for me, my updated code = @ http://jsfiddle.net/PbZRF/27/

$('.brand').on('change',function() {

        $checked = $('.brand:checked'); //perform selection only once

        if ($checked.length){ //checks if there are checked elements at all
           $('.merk').hide(); //hide all
           $checked.each(function(){
               $('li#m_' + $(this).attr('id') + '').show(); //show only the items with corresponding checkboxes
           });
        } else { //no checked elements
           $('.merk').show(); //show all
        }

    });

    <input type="checkbox" class="brand" id="Gazelle" />
    <input type="checkbox" class="brand" id="Batavus" />
    <input type="checkbox" class="brand" id="Trek" />
    <input type="checkbox" class="brand" id="KogaMiyata" />


    <li class="merk" id="m_Gazelle" style="display:block;">
    Gazelle
    </li>

    <li class="merk" id="m_Batavus" style="display:block;">
    Batavus
    </li>

    <li class="merk" id="m_Trek" style="display:block;">
    Trek
    </li>

    <li class="merk" id="m_KogaMiyata" style="display:block;">
    KogaMiyata
    </li>
  • 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-31T22:31:49+00:00Added an answer on May 31, 2026 at 10:31 pm

    You could use the :checked-pseudoclass to do it a little something like this:

    $('.brand').on('change',function() {
        $('.merk').hide(); //hide all
        $('.brand:checked').each(function(){
            $('li#m_' + $(this).attr('id') + '').show(); //show only the items with corresponding checkboxes
        });
    
    });​
    

    See: http://jsfiddle.net/PbZRF/16/

    EDIT: Responding to your comment you can just check the .length of the $('.brand:checked') selection and “take measures” in case it returns 0 / is falsy:

    $('.brand').on('change',function() {
    
        $checked = $('.brand:checked'); //perform selection only once, otherwise you'll get snarky comments around here :P - also best practice, so do it
    
        if ($checked.length){ //checks if there are checked elements at all
           $('.merk').hide(); //hide all
           $checked.each(function(){
               $('li#m_' + $(this).attr('id')).show(); //show only the items with corresponding checkboxes
           });
        } else { //no checked elements
           $('.merk').show(); //show all
        }
    
    });​
    

    See: http://jsfiddle.net/PbZRF/27/

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

Sidebar

Related Questions

I've been working all day and I somehow can't get this probably easy task
I have been working all night and yesterday on this header section in css,
I have been working all day but unable to achieve this : It is
I've been working at this all day, and I'm really close but just can't
been working all day on something and can't seem to get this right... I
I've been working on this all day now, and I just can't get it
This is a stupid simple question, but ive been staring at it all night
I have been working on this all day with no luck. Its night now
been banging my head on the table over this all night. I'm simply trying
I have been working on this Tab View and I finally got it working

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.