I can reduce the behavior to a simplest case (tested in the latest Chrome, Safari, Firefox, IE 9 and 10 (jsfiddle doesn't work on IE 8)):
$("input").click(function (evt) {
console.log("click event handler invoked", evt);
console.log($("input").attr("checked"));
console.log($("input").prop("checked"));
console.log($("input").is(":checked"));
});
$("input").click();
with the HTML:
<input type="checkbox"></input>
The output is:
undefined
false
false
so is it supposed to be correct that it should report the checkbox is not checked?
If it is correct, then why in jQuery 1.9.1, the behavior is completely the opposite? http://jsfiddle.net/fjvqa/2
If it isn't correct, I wonder why such a simple bug would be there still in jQuery 1.8.3, which was released Nov 13, 2012, which is just about 4 months ago... for such an obvious bug?
P.S. I do understand that (1) the attr()
should not be used but prop()
should be used instead. I print it out just to see what's happening. (2) the change
handler actually will report the opposite of what click
reports if using jQuery 1.8.3: http://jsfiddle.net/fjvqa/3 if it is jQuery 1.9.1, they report the same thing: http://jsfiddle.net/fjvqa/4 What I am looking for is what is the real situation of what is supposed to happen.