O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required