jQuery responds to click() differently for user and programmatic triggers

Posted by Moss on Stack Overflow See other posts from Stack Overflow or by Moss
Published on 2010-05-24T14:08:59Z Indexed on 2010/05/24 14:11 UTC
Read the original article Hit count: 139

Filed under:
|

Here's the code:

this.Form.find("input[type=checkbox]").click(function(event) {
    if ($(this).is(":checked")) {
        console.log("checked");
    }
    else {
        console.log("unchecked");
    }
});

If the checkbox is not checked, and I click with the mouse, I get "checked". If I trigger it programmatically like $("#someCheckbox").click(), I get "unchecked". How to make the two behave the same way?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about events