<div id="prod">
<div class="content" data-brand="Andrew" data-price="1000" data-store="JCPenny">Andrew</div><br />
<div class="content" data-brand="Hill" data-price="1200" data-store="JCPenny">Hill</div><br />
<div class="content" data-brand="Andrew" data-price="2000" data-store="JCPenny">Andrew</div><br />
<div class="content" data-brand="Hill" data-price="800" data-store="SuperMart">Andrew</div><br />
<div class="content" data-brand="Hill" data-price="1300" data-store="SuperMart">Hill</div><br />
<div class="content" data-brand="Andrew" data-price="800" data-store="JCPenny">Hill</div><br />
<input type="checkbox" class="brand" id="Andrew">Andrew
<input type="checkbox" class="brand" id="Hill">Hill
<input type="checkbox" class="store" id="JCPenny">JCPenny
<input type="checkbox" class="store" id="SuperMart">SuperMart
</div>
//checkBox();
$('input[type="checkbox"]').change(function(){
alert("check");
var a=$("input.brand");
var b=$("input.store");
var brand="";
var store="";
if($(a).is(":checked")) {
alert("brand checked");
$('#prod >div').hide();
brand=$(this).attr('id');
console.log(brand+","+store);
displaydivs(brand,store);
}
else{
$('#prod >div').show();
brand=""
displaydivs(brand,store);
}
});
function displaydivs(brand,store)
{
if(brand!="" & store!=""){
alert(brand);
alert(store);
$("#prod >div").hide();
$("#prod >div[data-store="+store+"][data-brand="+brand+"]").show();
}
else if(brand!="" & store==""){
$("#prod >div").hide();
$('#prod >div[data-brand="'+brand+'"]').show();
}
else if(brand=="" & store!=""){
$("#prod >div").hide();
$("#prod >div[data-store="+store+"]").show();
}
}
I created a code regarding my div filteration.In this code i am having data-brand and data-store as two attributes of div and i m having checkboxes related to these divs as ids brand and store respectively.When i m filtering with brand or store at one time.like if u selected one brand or one store checkbox(either of them),it filters correctly based on selection.lets say u selected one of the store checkbox.then we made second selection from store checkbox list.then we should be able to see both the selected stores list.i.e.Both JCPenny and Super mart divs should be shown,not the earlier selected.But when i m selecting for second time store checkbox list ,its hididng the first selected checkbox related divs and displaying the second or latest selected checkbox div s.Similar issue is for Brand checkbox. Please help on this......its very important for me...
Please help on this...
See Question&Answers more detail:os