I'm trying to monitor any changes to the "checked" property of a checkbox on both mousedown() and mouseup(), but seem to be having issues. The mousedown event is registering the correct state of the checkbox (checked or un-checked), but the mouseup event is registering those states in reverse.
If the checkbox is checked on mouseup, the mouseup event is saying it's un-checked, and if the checkbox is un-checked on mouseup, the event is saying it's checked. Any ideas what's going on here?
Here's the pertinent code:
$('.input-wrapper input[type=checkbox]').mousedown(function() {
console.log('===== MOUSEDOWN =====');
if (this.checked) {
console.log('The checkbox already had the "checked" attribute on mousedown');
}
if (!this.checked) {
console.log('The checkbox did NOT have the "checked" attribute on mousedown');
}
console.log('\n\n');
}).mouseup(function() {
console.log('===== MOUSEUP =====');
if (this.checked) {
console.log('The checkbox was assigned the "checked" attribute on mouseup');
}
if (!this.checked) {
console.log('The checkbox\'s "checked" attribute was removed on mouseup');
}
console.log('\n\n');
});
...
I've also setup a demo on jsFiddle, here.