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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:22:02+00:00 2026-05-29T11:22:02+00:00

based my previous question asked here: Jquery Filter List DIVs via checkboxes i got

  • 0

based my previous question asked here:
Jquery Filter List DIVs via checkboxes
i got in the situation when both checkboxes and the list is generated from javascript so if i look in view source i could’t see them .
I manage to find out that i could access the checkboxes via:

$(".bedroomType").attr("type", "input").change(function(){}

but i can’t make the list to filter…
How should be changed in this case this code?

 $(".bedroomType").attr("type", "input").change(function(){
   $(".bedroomType").attr("type", "input").each(function(){

        var checked = $(this).attr('checked') || false;
        var numberofrooms = $(this).data('bedrooms');
        alert(numberofrooms);
        $('.listing').each(function(){
            if ($(this).data('bedrooms')==numberofrooms){
                checked ? $(this).show() : $(this).hide();
            }
        });
    });

thank you

  • 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-29T11:22:02+00:00Added an answer on May 29, 2026 at 11:22 am

    Your sample code won’t work because you cannot give the filter authority to both show() AND hide() items in the listing. In general, a filter should either show() OR hide() (or similar), and in this case it should hide().

    You will find it more convenient to organise the code into a ‘master’ filter that calls the ‘bedroom’ filter and (eventually) other filters. The master should ensure that all listing items are initially shown, so that the filters can selectively hide them.

    It is tempting to think that you could alternatively do things the other way round – namely to hide() all items initially, then allow the filters to selectively show(). But this would not work because no individual filter should have the authority to show() – other filters may have a different opinion! With a filter-set of this type, you want items to show only if they meet ALL criteria, not ANY one.

    Here’s some code:

    function filterListingByBedrooms($listing){
        var selectedBeds = [];
        $(".bedroomType").each(function(){
            if(this.checked) {
                selectedBeds.push($(this).data('bedrooms'));//build array of checked bedroom numbers
            }
        });
        $listing.each(function(){
            var $this = $(this);
            if(!$.inArray($this.data('bedrooms'), selectedBeds)) {
                $this.hide();
            }
        });
    }
    
    function filterListingByType($listing){
        ...;
    }
    
    function filterListingByLocation($listing){
        ...;
    }
    
    function filterListing(){
        var $listing = $('.listing').show();//Initially show all, then allow filters to selectively hide.
        filterListingByBedrooms($listing);
        filterListingByType($listing);//apply other filter
        filterListingByLocation($listing);//apply other filter
    };
    
    $(".bedroomType").change(filterListing);
    $(".propertyType").change(filterListing);
    $(".location").change(filterListing);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bit of a problem here. Based on my previous question asked
Based on my previous question here my new concern is how do I unit
Based on my previous question here and here , I found that I can
Based off of a previous question I asked, which @Andrie answered, I have a
Based on a previous question, where I asked about IDEs to support development in
In a previous question I asked how I could sum up a total based
Based on a previous question and with a lot of help from Damir Sudarevic
I have a problem with populating an autocomplete list based on a previous input.
Possible Duplicate: What does ||= mean? In this previous question, I asked about an
Based on my previous question , I've come up with a better way 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.