JQuery Trigger checkbox: function attached to click event before set attribute set

I implement a function like "Billing address, similar to the function" Address ", which, when checked, fills the fields based on other fields. Works great.

Click event function.

    if ($(this).attr('checked')) {
        // copy address fields to billing fields
    }
    else{
        // clear fields
    }

Now I use the event (jQuery hotkey plugin) to automatically fill in all the fields in the form so that I can quickly and easily demo and validate the form. Instead of cheating and filling in billing fields as address fields I want to use

$("#CheckboxForAutofillId").trigger('click'); 

This does not work the first time I fire the event, because in the above function, which is called, it checks the checked attribute, however, the trigger ('click') seems to trigger the event BEFORE it changes the attribute.

, , .

$("#CheckboxForAutofillId").attr("checked", "checked"); // sets checked
$("#CheckboxForAutofillId").trigger('click');           // fires event then 'unchecks'
$("#CheckboxForAutofillId").attr("checked", "checked"); // rechecks

jquery , , , , , , "checked" ' , , ?

- ?

+5
1

change() click().

$("#CheckboxForAutofillId").change(function()
{
    if(this.checked) ...
});
+8

All Articles