setAttribute & removeAttribute with checkbox

Let say, we have a checkbox and button to toggle on/off for checkbox

then some javascript for click event of button

Now if you click on the button, you can see, it is working fine, but, the big “BUT”,
click on the checkbox first and then click on the button. !Its not working any more! as we expected.

I don’t know the reason why it is not working, somehow, I know how to fix it.
So instead of setAttribute and removeAttribute, use something like


Leave a Reply

Your email address will not be published. Required fields are marked *