I have a form that contains checkboxes, and from the script I check and uncheck them according to some requirements. at a certain point I reset the form $("#formId")[0].reset()
, all inputs get reseted exept for checkboxes!!
I reseted the form but checkboxes didn’t get reseted.
2
Answers
attr('checked', true)
I switched toprop('checked', true)
and it worked.attr()
adds an attribute checked to the input (checked="checked"
) whileprop()
doesn't add anything. I also found thatprop()
is newer and was released in version 1.6, whileattr()
in version 1.0So I advice you to use
prop()
more often thanattr()
Please check my code and let me know if you find any issue