title: jQuery - Dynamically Create Button and Attach Event Handler
body: <p>I would like to dynamically add a button control to a table using jQuery and attach a click event handler. I tried the following, without success:</p>
  
  <pre><code>$("#myButton").click(function () {
      var test = $('&lt;button&gt;Test&lt;/button&gt;').click(function () {
          alert('hi');
      });
  
      $("#nodeAttributeHeader").attr('style', 'display: table-row;');
      $("#addNodeTable tr:last").before('&lt;tr&gt;&lt;td&gt;' + test.html() + '&lt;/td&gt;&lt;/tr&gt;');
  });</code></pre>
  
  <p>The above code successfully adds a new row, but it doesn't handle adding the button correctly. How would I accomplish this using jQuery?</p>