KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Update: This only applies to jQuery 1.8 and below. This was fixed in jQuery 1.9 . Here is my minimal jsfiddle example: http://jsfiddle.net/8fuEJ/ . I'm using Google Chrome, if that makes a difference. I have a checkbox: <input type="checkbox" id="wtf"> And I have a jquery event handler: $('#wtf').click(function(ev) { alert(this.checked); }); So far, so good. When I click the checkbox, I first see the checkmark appear, then the alert "true" (in that order). When I click it again, I see the checkmark disappear, then the alert "false". The problem comes when I programmatically trigger the click event. Like this: $('#wtf').click(function(ev) { alert(this.checked); }); $('#wtf').click(); In this case, first I see the alert "false" (with the checkmark still not visible), then after dismissing the alert, the checkmark appears. Why the difference in order here? Also note that if I use the event handler change , it works as expected. $('#wtf').change(function(ev) { alert(this.checked); }); $('#wtf').click(); Here, I see the checkmark appear, then the alert "true".
Tags (comma-separated)
Save Edits
Cancel