title: refactor this javascript code
body: <p>I have two click-events, that are nearly similar, but not quite. I am wondering how to refactor them best:</p>
  
  <pre><code>  $('.remove_fields.dynamic').live('click', function(e) {
      var $this = $(this);
      var after_removal_trigger_node = $this.closest(".nested-fields").parent();
      trigger_removal_callback($this);
      e.preventDefault();
      $this.closest(".nested-fields").remove();
      trigger_after_removal_callback(after_removal_trigger_node);
    });
  
    $('.remove_fields.existing').live('click', function(e) {
      var $this = $(this);
      var after_removal_trigger_node = $this.closest(".nested-fields").parent();
      trigger_removal_callback($this);
      e.preventDefault();
      $this.prev("input[type=hidden]").val("1");
      $this.closest(".nested-fields").hide();
      trigger_after_removal_callback(after_removal_trigger_node);
    });
  </code></pre>
  
  <p>As you can tell there is a fair bit of overlap. I am wondering what the best/nicest way would be to refactor this code.</p>