Guest User

Untitled

a guest
Jan 18th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. <fieldset>
  2.     <div class="col-md-6 test-one"><label><input id="example-category-1" type="checkbox" value="first-checkbox" />CHOOSE CATEGORY 1</label></div>
  3.     <div class="col-md-6 test-one"><label><input id="example-category-2" type="checkbox" value="second-checkbox" />CHOOSE CATEGORY 2</label></div>
  4. </fieldset>
  5.  
  6. var test = true;
  7.     $(".test-one").change(function() {
  8. if(test){    
  9.             $('div[data-product]').parents("li").hide();
  10. //hide every product after first click on any checkbox
  11.             
  12.             if( $('#example-category-1').is(':checked') ) {
  13. //check for checkbox activation and show products if true
  14.                 $('div[data-product="1802"]').parents("li").show();
  15.                 $('div[data-product="1781"]').parents("li").show();
  16.             }
  17.             if( $('#category-2').is(':checked') ) {
  18. //check for checkbox activation and show products if true
  19.                 $('div[data-product="1348"]').parents("li").show();
  20.                 $('div[data-product="1347"]').parents("li").show();
  21.             }
  22.             test =false;
  23. //set to false so we don't enter this if statement again
  24.         }
  25.     });
  26.  
  27. $('#example-category-1').click(function() {
  28.         if( $(this).is(':checked') ) {
  29.             $('div[data-product="1802"]').parents("li").show();
  30.             $('div[data-product="1781"]').parents("li").show();
  31.         } else {
  32.             $('div[data-product="1802"]').parents("li").hide();
  33.             $('div[data-product="1781"]').parents("li").hide();
  34.         }
  35.     });
  36.     $('#example-category-2').click(function() {
  37.         if( $(this).is(':checked') ) {
  38.             $('div[data-product="1348"]').parents("li").show();
  39.             $('div[data-product="1347"]').parents("li").show();
  40.         } else {
  41.             $('div[data-product="1348"]').parents("li").hide();
  42.             $('div[data-product="1347"]').parents("li").hide();
  43.         }
  44.     });
Add Comment
Please, Sign In to add comment