title: How to attach jQuery UI datepicker to dynamically inserted formfield?
body: <p>I have a table containing a bunch of input fields, sort of like a spreadsheet.  Some of the input fields use the jQuery UI datepicker.  There is also a button to add a table row.  </p>
  
  <p>When I click the button to add a table row, it is added to the DOM correctly.  But, the datepicker widget doesn't get attached to the date fields in that new row.</p>
  
  <p>I suspect the answer is to use live() - or maybe on() - to call datepicker(), but I don't understand what  syntax to use.  The code below is already pushing the limits of my jQuery understanding. My head hurts. Help?</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(function() {
          $( ".usedatepicker" ).datepicker();
      });
  
      $('.rowadd').live('click',function(){
          var appendTxt = '&lt;tr&gt;&lt;td&gt;&lt;input class="usedatepicker" name="something" type="text" /&gt;&lt;/td&gt;&lt;/tr&gt;';
          $("tr:last").after(appendTxt);
      });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Note 2:  I've tried this as well, with both live() and on().  It seems to work on both the original fields and the dynamically inserted ones, but sporadically (at least in Chrome).  Like, it'll work for three seconds and then stop for three seconds, and then work for three seconds and...</p>
  
  <pre><code>$(function() {
      $('.usedatepicker').live('click', function(){
          $(this).datepicker({showOn:'focus'});
      });
  });
  </code></pre>