Toggle text when the checkbox is selected and deselected

javascript, jquery

Solution

Javascript...

window.onload = function() {
  var chk = document.getElementById('CheckboxIdHere')
  chk.onclick = function() {
    var lbl = document.getElementById('LabelIdHere')
    lbl.innerHTML = (this.checked) ? "Yes" : "No";
  }
}

jQuery...

$(function() {
  $("#CheckboxIdHere").click(function() {
    $("#LabelIdHere").html(($(this).is(":checked")) ? "Yes" : "No");
  });
});

Problem

I have a check box with text next to it. I want to toggle the text 'YES' or 'NO' when the checkbox is selected and deselected. I am having a hard time with this, does anyone have an example of this? I can't get Jquery to respond to the state of the checkbox.

Original source