I found the problem. In your first attempt, you are using
attr()
and
removeAttr()
methods.
Refer -
Add attribute 'checked' on click jquery[
^].
Quote:
In IE, this will always actually make the checkbox checked. In other browsers, if the user has already checked and unchecked the checkbox, setting the attribute will have no visible effect. Therefore, if you want to guarantee the checkbox is checked as well as having the checked
attribute, you need to set the checked
property as well:
Then in your next attempt, you corrected the code to deal with the
checked
property instead of attribute.
$("#" + parentdvId + " input:checkbox").prop("checked", true);
$("#" + parentdvId + " input:checkbox").prop("checked", false);
As I was debugging, suddenly it came to my mind that, when the code ran for the first time, it removed the attributes all together from the
CheckBoxes
, so how it would work next time. Then I researched more and find out that we should set the property instead of attribute.