title: How to handle programmatic change of the input element state in javascript
body: <p>I've faced strange problem. While user change of check box input element on form produces adequate event programmatic change don't. How should I face this challenge? Code following:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
    &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript"&gt;
      jQuery(document).ready(
        function() {        
          jQuery("#cb").change(
            function() {
              alert("Changed!"); 
              return true;
            }
          );
          jQuery("#b").click(
            function() {
              var newState = !jQuery("#cb").attr('checked');
              jQuery("#cb").attr('checked', newState);
            });
        });
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;form action="#"&gt;
      &lt;p&gt;
        &lt;input type="button" id="b" /&gt;
        &lt;input type="checkbox" id="cb" /&gt;
      &lt;/p&gt;
    &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Update</strong>
  I do not control element changes, I just need to handle them. It's general-propose code I write.</p>