Can anyone explain why $(this).is(":checked")
gives the opposite result when the checkbox is clicked with $("#test").click()
than when clicked manually or with document.getElementById("test").click()
??
EDIT Requested behavior here - thanks:
http://jsfiddle.net/ub8Zk/4/
EDIT 2
This has been driving me nuts, but I finally realize -- in version 1.5.2 of jQuery the event handler for the change
event is fired when click()
method is called (like native js)!! Not so in previous versions.
Look here:
http://dl.dropbox.com/u/6996564/jquery_click_test/test-1.4.4.htm ... test-1.5.1.htm ... test-1.5.2.htm
Can someone help me report this bug??
The click event happens BEFORE the value changes, so it is getting the old value. The the default handler for click happens AFTER your click event and toggles the value. That is why it is getting the opposite value. I would think the document click function is doing something wierd (I would not trust it, I would trust jQuery).
Look at this fiddle: http://jsfiddle.net/ub8Zk/4/
Since you are using a checkbox input, you want is(':checked')
not is(':selected')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With