0

So I'm using jQuery to skin some form checkboxes, and am doing something like the following:

$('.sexyCheckBox').on("click", function(e) {
    var clickedInput = $(this).parent().find("input");
    clickedInput.prop("checked", !clickedInput.prop("checked"));
}

However, it seems that, even though the checkbox in form is indeed being toggled, the form's .change() event is not being called.

Is this a bug in jQuery or am I missing something?

1 Answer 1

3

Programatic changes to inputs value does not fire the change event, you need to trigger it manually. The change event will be triggered only if the user changes the value of an input element.

clickedInput.prop("checked", !clickedInput.prop("checked")).change();

another way to write this is

clickedInput.prop("checked", function (i, val) {
    return !val;
}).change();//or .trigger('change')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.