[jQuery] defaultChecked VS checked

Read Time:39 Second

jQuery defaultchecked VS checked


I have checkbox elements on div(‘#dialog-a’) for a dialog. When an user clicks a button, then jQuery will bring the dialog with html code of div(‘#dialog-a’). Once, the user set checkbox and click “Close” button in the dialog, “Close” function supposes to set checkbox as “checked” in div(‘#dialog-a’).

I use the javascript code to set original checkbox as below:
$(“#elm_check”, “#hidden-area”).attr(“checked”, true);
However, the issue occurs in here. The original checkbox does not remain as “checked” state, when the dialog opens again.


Use the javascript as below:
$(“#elm_check”, “#hidden-area”).attr(“defaultChecked”, true);

Caution: Interestingly, ‘defaultChecked’ is case-sensitive. If you apply ‘defaultchecked’, it was not working.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.