title: Set onclick handler to dynamically created button
body: <p>I need to create button dynamically and assign its <code>onclick</code> handler. Click handler could be anonymous function (I'm not sure how it is called in JS). It is allowed to <code>jQuery</code>.<br>
  I tried something like this:</p>
  
  <pre><code>&lt;div&gt;
      &lt;button id="x"&gt;Show&lt;/button&gt;
  &lt;/div&gt;
  
  function magick() {
      console.log('some special magick');
  }
  
  function createButton(itsHandler) {
      var guts = '&lt;button id="__internal" onclick="' 
          + itsHandler +    // &lt;-- that's wrong
          '"&gt;Test&lt;/button&gt;';
      $($.trim(guts)).appendTo('body');
  }
  
  $(document).ready(function () {
      $("#x").bind("click", function() { 
              createButton(magick);
          });
  });
  </code></pre>
  
  <p>but is doesn't work.</p>
  
  <p>(<a href="http://jsfiddle.net/evgeny_t/3dnmu/" rel="nofollow">Here is jsfiddled code</a>)</p>
  
  <p><em><strong>How it can be accomplished?</em></strong><br>
  <strong><em>UPD1</em></strong>: It would be better if it was done inside of the <code>createButton</code> function.</p>