$(function () {
var $checkbox = $("#checkbox");
var $results = $("#results");
var count = 1;
$("#toggleCheckboxValue").on("click", function () {
var isChecked = $checkbox.is(":checked");
$checkbox.prop("checked", !isChecked);
});
$("#getCheckboxValue").on("click", function () {
var isChecked = $checkbox.is(":checked");
$results.prepend("<div>" + count++ + ". The value of the checkbox is: " + isChecked + "</div>");
});
});
<div>
<input id="checkbox" type="checkbox" />
<span>Check or uncheck the checkbox and click the "Get Checkbox Value" button.</span>
</div>
<div>
<button id="toggleCheckboxValue">Toggle Checkbox Value</button>
<button id="getCheckboxValue">Get Checkbox Value</button>
</div>
<h2>Results</h2>
<div id="results">
</div>
<div style="position: absolute;bottom: 5px;">
Read about this Fiddle at: <a href="http://jsdev.wikidot.com/howto:6" target="_blank">How To: jQuery - Get and Set a Checkbox Value</a>
</div>
body > div {
margin-bottom: 20px;
}
button {
margin-right: 10px;
}
#results {
min-height: 50px;
border: 1px solid lightgrey;
padding: 5px;
}
External resources loaded into this fiddle: