title: jQuery plugin and append
body: <p>I have written a 'plugin' for add &amp; edit items to a list. Adding and editing is working fine for existing items, but it doesn't work for a new item which is added via <code>.before()</code>. I make use of the following script, which isn't optimal I think?</p>
  
  <pre><code>&lt;div id="test"&gt;
    &lt;div class="item"&gt;Test&lt;/div&gt;
    &lt;div class="add"&gt;Add item&lt;/div&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
  (function ($) {
  
      $.fn.pim = function() {
          $(this).click(function() {
  
              if ($(this).hasClass('add')) {
                  $($(this)).before('&lt;div class="item"&gt;Test&lt;/div&gt;');
              } else {
                  alert('Edit succes');
              }
          });
  
      }
  
  }(jQuery));
  $("#test div").pim();
  &lt;/script&gt;
  </code></pre>