title: jquery loop function forever?
body: <p>I am using the following jquery script which changes the colour of a checkbox to red when a user has clicked on it, and to black when it is unchecked.</p>
  
  <p>The checkbox starts of black as it is unchecked, then when a user clicks in the checkbox it changes the background of the checkbox to red.</p>
  
  <p>My problem is this, if a user checks the checkbox the first time this goes from black to red, then if they uncheck the checkbox it goes back to black. However for whatever reason if they want to re-check the checkbox it does not go back to red?</p>
  
  <p>Is there a way in which I can make this function run on a loop? thanks in advance...</p>
  
  <pre><code>&lt;script&gt;
      $(this).children("input").attr("checked");
      $(document).ready(function() {
  
  // assuming all checkboxes are unchecked at first
  $("span[class='checkbox']").addClass("unchecked");
  
      $(".checkbox").click(function(){
          if($(this).children("input").attr("checked")){
              // uncheck
              $(this).children("input").attr({checked: ""});
              $(this).removeClass("checked");
              $(this).addClass("unchecked");
          }else{
              // check
              $(this).children("input").attr({checked: "checked"});
              $(this).removeClass("unchecked");
              $(this).addClass("checked");
          }
  
  
      });
  });
  &lt;/script&gt;
  </code></pre>