jQuery (original answer)
jQuery(document).ready(function() {
jQuery('#showCheckoutHistory').change(function() {
if ($(this).prop('checked')) {
alert("You have elected to show your checkout history."); //checked
}
else {
alert("You have elected to turn off checkout history."); //not checked
}
});
});
Documentation here: http://api.jquery.com/prop/
JavaScript (2018 update)
It is worth to notice, that you don't need any javascript libraries to acomplish that.
// Check current state and save it to "checked" variable
var checked = document.getElementById("showCheckoutHistory").checked;
// Set state manually (change actual state)
document.getElementById("showCheckoutHistory").checked = true; // or
document.getElementById("showCheckoutHistory").checked = false;
For more pure javascript solutions I recommend vanilla.js: http://vanilla-js.com/ framework ;)