title: Jquery - Checkbox staying checked - simple filter system
body: <p>I am building a very simple filter system where I want to have html checkboxes that can show and hide items of particular categories.</p>
  
  <p>The problem is that the checkboxes stay checked no matter what.</p>
  
  <p>Example on jsfiddle: <a href="http://jsfiddle.net/Jmnwr/" rel="nofollow noreferrer">http://jsfiddle.net/Jmnwr/</a></p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;ul id="filters"&gt;
      &lt;li&gt;&lt;input type="checkbox" checked="checked" value="categorya" id="filter-categorya" /&gt;&lt;label for="filter-categorya"&gt;Category A&lt;/label&gt;&lt;/li&gt;
      &lt;li&gt;&lt;input type="checkbox" checked="checked" value="categoryb" id="filter-categoryb" /&gt;&lt;label for="filter-categoryb"&gt;Category B&lt;/label&gt;&lt;/li&gt;
  &lt;/ul&gt;
  
  &lt;div class="categorya"&gt;&lt;/div&gt;
  &lt;div class="categorya"&gt;&lt;/div&gt;
  &lt;div class="categorya"&gt;&lt;/div&gt;
  &lt;div class="categorya"&gt;&lt;/div&gt;
  &lt;div class="categoryb"&gt;&lt;/div&gt;
  &lt;div class="categoryb"&gt;&lt;/div&gt;
  &lt;div class="categoryb"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>JS:</p>
  
  <pre><code>$("#filter-categorya").toggle(
  function() {
      $('.categorya').stop().fadeTo('slow', 0.2);
      $('#filter-categorya').removeAttr('checked');
  }, function() {
      $('.categorya').stop().fadeTo('slow', 1.0);
      $('#filter-categorya').attr('checked', 'checked');
  });
  
  $("#filter-categoryb").toggle(
  function() {
      $('.categoryb').stop().fadeTo('slow', 0.2);
      $('#filter-categoryb').removeAttr('checked');
  }, function() {
      $('.categoryb').stop().fadeTo('slow', 1.0);
      $('#filter-categoryb').attr('checked', 'checked');
  });
  </code></pre>
  
  <p>I have seen two posts regarding this topic but not sure if they are entirely related or why my code in particular is not working. I've also tried using the preventdefault function but it didn't do anything:</p>
  
  <p><a href="https://stackoverflow.com/questions/4307272/unable-to-control-checkbox-checked-status-jquery">Unable to control checkbox checked status - jquery</a>
  <a href="https://stackoverflow.com/questions/2596854/why-wont-attrchecked-checked-set">Why won&#39;t .attr(&#39;checked&#39;,&#39;checked&#39;) set?</a></p>
  
  <p>Any help always appreciated,
  Thanks!</p>