title: Jquery toggle event is messing with checkbox value
body: <p>I'm using Jquery's toggle event to do some stuff when a user clicks a checkbox, like this:</p>
  
  <pre><code>$('input#myId').toggle(
  function(){
  //do stuff  
  },
  function(){
  //do other stuff    
  }
  );
  </code></pre>
  
  <p>The problem is that the checkbox isn't being ticked when I click on the checkbox. (All the stuff I've put into the toggle event is working properly.)</p>
  
  <p>I've tried the following:</p>
  
  <pre><code>$('input#myId').attr('checked', 'checked');
  </code></pre>
  
  <p>and</p>
  
  <pre><code>$(this).attr('checked', 'checked');
  </code></pre>
  
  <p>and even simply</p>
  
  <pre><code>return true;
  </code></pre>
  
  <p>But nothing is working. Can anyone tell me where I'm going wrong?</p>
  
  <p>Edit - thanks to all who replied. Dreas' answer very nearly worked for me, except for the part that checked the attribute. This works perfectly (although it's a bit hacky)</p>
  
  <pre><code>$('input#myInput').change(function ()
  {
      if(!$(this).hasClass("checked"))
      {
          //do stuff if the checkbox isn't checked
          $(this).addClass("checked");
          return;
      }
  
      //do stuff if the checkbox isn't checked
      $(this).removeClass('checked');
  });
  </code></pre>
  
  <p>Thanks again to all who replied.</p>