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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:30:16+00:00 2026-06-11T18:30:16+00:00

I am using jQuery to filter product items on a page (hide and display

  • 0

I am using jQuery to filter product items on a page (hide and display DIVs) I am using filter as a replacement since PHP $_GET is a bit old fashion we’re trying to do this via jQuery. I using filter() and data attribute.

How can I turn off the current selection of checkboxes except the existing item?
How can I hide the items based off selection and unhide when not?

HTML

<input type="checkbox" id="drama" onClick="filterCategory(this.value)" value="drama" /> Drama<br />
<input type="checkbox" id="romance" onClick="filterCategory(this.value)" value="" /> Romance<br />
<input type="checkbox" id="horror" onClick="filterCategory(this.value)" value="horror" /> Horror<br />

<!--------------------->
<div class="products">
    <div class="productItem" data-price="250" data-category="horror">
        Scary Book
        <div class="productItemPrice"><span>&pound;250</span></div>
    </div>
    <div class="productItem" data-price="150" data-category="drama">
        Drama Poems
        <div class="productItemPrice"><span>&pound;150</span></div>
    </div>
    <div class="productItem" data-price="250" data-category="romance">
        Love Story
        <div class="productItemPrice"><span>&pound;250</span></div>
    </div>
    <div class="productItem" data-price="241" data-category="horror">
        Creep Book
        <div class="productItemPrice"><span>&pound;241</span></div>
    </div>
</div>
<!--------------------->

jQUERY

function filterCategory(id) {
    var pid=$(".productItem"); // Which product is it
    var checkid=$('#'+id); // The name of the checkbox form
    var cid=$(pid).data("category"); // The value of the checkbox form
    if ($(checkid).is(':checked')){
        $(pid).hide().filter(function () {var catId=$(this).data("category");return catId;}).show();
    } else {
        $(pid).show().filter(function () {var catId=$(this).data("category");return catId;}).show();
    }
}

CSS

.productItem{float:left;padding:5px;margin:5px;border:1px solid #eaeaea}
body{font-family:verdana}

JSFiddle

http://jsfiddle.net/RyZy8/

  • 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-11T18:30:17+00:00Added an answer on June 11, 2026 at 6:30 pm

    You could try using something like this instead,

    Firstly remove the onclick attribute on the checkboxes – use jQuery to bind the click event :

    // bind to click
    $('input[type="checkbox"]').click(function() {
        // any checked
        if ($('input[type="checkbox"]:checked').length > 0) {
            // hide all
            $('.products >div').hide();
            // loop checked and display relavent div
            $('input[type="checkbox"]:checked').each(function() {
                $('.products >div[data-category=' + this.id + ']').show();
            });
        } else {
            // none checked - show all
            $('.products >div').show();
        }
    });​
    

    Working example here

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

Sidebar

Related Questions

I am working on a filter functionality using ajax/jquery and php/mysql.I have two sets
I've created a page using JQuery and Ajax that helps a user filter through
I want to filter a table using jQuery hide/show based on what the user
I have page, that loads in data using AJAX (a form filter) using jQuery.
Ok so I’m using the quicksand jquery filter. now I want to add a
I have 2 dropdown lists on my webform and using jquery trying to filter/reset
I'm trying to implement chained filter dropdown using just javascript - jquery. The solution
using jquery's .post i send do my php code an object that with var_dump
I'm using jQuery :contains selector to filter through some link tags. The following code
I'm stuck trying to implement a user-configurable filter on a table using jQuery (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.