How to simulate a click event in jQuery
<p>note: all this is on chrome</p>

<p>I am trying to test something that responds to a click a checkbox. I realize jQuery.click() exists, but it seems to be different from a "native" click in that during the click handler, the state of the checkbox isn't updated yet (so checkbox is unchecked, you call .click(), in the handler, checkbox is still unchecked. If you actually click the box, in the handler the state is checked).</p>

<p>I apologize for the confusing question, here is a fiddle  <a href="http://jsfiddle.net/XBhWy/" rel="nofollow">http://jsfiddle.net/XBhWy/</a></p>

<p>Click the foo button, notice that button handler says it has been checked, but the checkbox handler says it has not been checked (even though the ui shows a checkmark). Now, click the checkbox itself. Notice the click event handler is reporting what you would expect it to report.</p>

<p>My question is how to simulate the same thing that happens when you actually click the box.</p>

<p>Now, I took a stab at a better simulated event like this</p>

<pre><code>$.fn.check = function() {
  if ($(this).is(':checked')) {
    $(this).attr('checked', 'checked');
  } else {
    $(this).removeAttr('checked');
  }
  $(this).click();
}
</code></pre>

<p>Unfortunately (and somewhat confusingly), it didn't work.</p>

<p>Anyone run into this before? Can it be accomplished?</p>

<p>Note that I'm not looking for the <code>click</code> method.</p>
