How To: jQuery - Get and Set a Checkbox Value

To get the checkbox value use the jQuery is method and pass in ":checked". To set the value of a checkbox, use the jQuery prop method for jQuery after version 1.6 or the attr method for jQuery version 1.6 or below.

Syntax

Get Checkbox Value

var isChecked = $("#checkbox").is(":checked");

Set Checkbox Value (jQuery version > 1.6)

$("#checkbox").prop("checked", true);

Set the Checkbox Value (jQuery version <= 1.6)

$("#checkbox").attr("checked", true);

Alternatively, the value of the checkbox can be set or retrieved by using the checked attribute of the DOM element.

Get Checkbox Value from DOM element

var isChecked = $("#checkbox")[0].checked;

Set Checkbox Value on the DOM element

$("#checkbox")[0].checked = true;

Example

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License