JSFiddle - React, Tailwind, and code Playground

by James

HTML

<div class="chkbox-container">
  <input type="radio" name="catfilter[]" value="all" checked="checked"/> All<br/>
  <input type="radio" name="catfilter[]" value="category1" /> Category 1<br/>
  <input type="radio" name="catfilter[]" value="category2" /> Category 2<br/>
  <input type="radio" name="catfilter[]"value="category3" /> Category 3<br/>
</div>
<div class="img-container">
  <img src="http://images2.fanpop.com/image/photos/9100000/kitty-kitties-9109284-500-460.jpg" rel="category1" />
  <img src="http://thedailycatblog.com/wp-content/uploads/2010/01/kitties-in-teacup1.jpg" rel="category2" />
  <img src="http://kecute.files.wordpress.com/2007/09/bunch-of-kitties.jpg?w=455" rel="category3" />
</div>

CSS

.chkbox-container{
  float:left;
  width:95px;
  border:1px solid #ccc;    
}
.img-container{
  float:left;
  width:300px;
  border:1px solid #ccc;    
}
img{
  display:inline-block;
  width:90px;
  height:75px;
  padding:2px;
  border:1px solid black; 
  display:none;    
}

JavaScript

$('.chkbox-container :radio').on('change', function(){
  var me = $(this);
  $.each($('.img-container img'), function(i,v){
    var theCats = $(v).attr('rel');
    theCats = theCats.split(' ');
    if($.inArray(me.val(), theCats)){
      $(v).show();
    }else{
      $(v).hide();
    }
      
  });        
});