Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

1
  • 1
    Your answer has a limitation. When the checkbox is checked or unchecked at least once by the end user, i.e not programmatically, it stops working, the same checkbox can no longer be checked or unchecked programmatically by setting this attribute. I've just tested under Mozilla Firefox 94.0.2 and Microsoft Edge 96.0.1054.43. However, document.getElementById('checkbox').checked = true and document.getElementById('checkbox').checked = false work as expected (but don't trigger a change event as stated in many posts). Commented Dec 7, 2021 at 13:52