Checking and Changing Check Box State

if ($("#myCheckbox").is(":checked)){   $("#myCheckbox").removeAttr("checked"); else{   $("#myCheckbox").attr("checked"); }

Check box input elements have a boolean value based on whether the element is checked. You access the value by getting the value of the checked attribute. If the element is checked, then checked has a value such as true or "checked". Otherwise, the value will be undefined or false.

You can get and set the state of a check box element from JavaScript in the following manner:

domObj.checked = true; domObj.checked = false; var state = domObj.checked;

Determining whether an item is checked with jQuery is a bit different. ...

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.