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

The Archive Base Latest Questions

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

I found this link where I got this code: $(document).ready(function(){ //when a link in

  • 0

I found this link where I got this code:

$(document).ready(function(){     
    //when a link in the filters div is clicked...  
    $('#filters a').click(function(e){        
        //prevent the default behaviour of the link  
        e.preventDefault();       
        //get the id of the clicked link(which is equal to classes of our content  
        var filter = $(this).attr('id');      
        //show all the list items(this is needed to get the hidden ones shown)  
        $('#content ul li').show();       
        /*using the :not attribute and the filter class in it we are selecting 
        only the list items that don't have that class and hide them '*/  
        $('#content ul li:not(.' + filter + ')').hide();      
    });       
}); 

It worked fine, but I’m using this code in a select button. When I choose the option, it filters ok.
But I have more than one select – 5 in fact -, but I don’t know how to approach in this situacion.

Example:
Items: strawberry, apple, cherry, orange, banana, grape
Select 1 – all fruits, red color, green color, etc
Select 2 – all forms, rounded form, triangle form.
Select 3 – all another thing, another thing

The user can first choose the color red – First Filter.
then he could choose rounded, so apple and cherry would be the answers.

I’ve already tried to filter only the visible images, but some error ocurred when I try do bring the information back.

In the same example with the results apple and cherry, if the users select all fruits the results must be apple, cherry, orange and grape.

Some advice?

Here is an example code
Note that the filters are working in isolated way.

  • 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-07T19:03:01+00:00Added an answer on June 7, 2026 at 7:03 pm

    Fiddled:

    http://jsfiddle.net/iambriansreed/turMe/

    jQuery:

    $(document).ready(function(){  
    
        var filters = {};
    
        //when a link in the filters div is clicked...  
        $('#filters a').click(function(e){        
            e.preventDefault();      
            filters[$(this).parent().attr('class')] = $(this).attr('id');      
            var show = $('#content ul li').filter(function(){                
                for(k in filters)
                    if(
                       filters.hasOwnProperty(k) &&
                       !$(this).hasClass(filters[k])
                    )
                    return false;            
                return true;                
            });
            show.show();            
            $('#content ul li').not(show).hide();            
            $('pre').html(JSON.stringify(filters));            
        });      
    }); ​
    

    HTML

    <!-- the filters div -->  
    <div id='filters'>
    <p>Filter One:</p>
    <p class="f1" >
        <a href='#' id='allitens'>All</a>
        <a href='#' id='bestof'>Best Of</a>
        <a href='#' id='jquery'>jQuery</a>
        <a href='#' id='php'>PHP</a>
        <a href='#' id='html'>HTML</a>
        <a href='#' id='css'>CSS</a> 
    </p>
    <p>Filter Two: Begins with letter or Number</p>
        <p class="f2">
    <a href='#' id='b1'>B</a> 
    <a href='#' id='n1'>1</a>
    <a href='#' id='H'>H</a>
        </p>
    </div>  
    
    
        <!-- the content div -->  
        <div id='content'>  
            <!-- the unordered list where we store the content in list items -->  
            <ul>  
              ...
            </ul>  
    </div>  
    Filters
    <pre></pre>
    

    I create an object which I then assign all the filters to. I then filter out the DOM elements that don’t meet the criteria. This will now work for any number of filters.

    On this line:

    filters[$(this).parent().attr('class')] = $(this).attr('id');
    

    I am doing three things:

    1. Getting the class attribute of the clicked link’s parent (the paragraph tag). $(this).parent().attr('class')
    2. Getting the ID of the clicked link.
      $(this).attr('id')
    3. Adding or overwriting a property of the object filters using the key defined in 1 and the value defined in 2.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem using the Catch Clipboard Events code found on this link
I've found a code which opens this link after logging in to google account
I got this code: Link I can highlight the chars of static text by
I found this link Link to another page using Twitter Bootstrap jquery modal in
I found this link on how to embed custom fonts in XAML apps. Is
I have found this link: http://www.jfree.org/forum/viewtopic.php?f=3&t=6314 Its back in 2007 where they agree that
I've search for some solution to my problem and I found this link .
Trying to build openssl-fips-2.0 with NDK, before I was lucky found this link and
I need to make rate option in my android app. I found this link
I found from this link that there are several types of XML parsers in

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.