title: Previously clicked items being removed by modal
body: <p>I have a modal that allows me to remove an <code>.item</code>.</p>
  
  <p>Once I click on an item, the modal will appear and I can either select "confirm" or "cancel". If I select cancel for multiple items, but then on one item select "confirm", every previous clicked item will be removed.</p>
  
  <p>How can I prevent this?</p>
  
  <p>I have tried setting the variable <code>item</code> to <code>null</code> within the modal open function, then resetting the variable directly after, but that did not work.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function() {
  
    var modal = $('.modal');
  
    $(document).on('click', '.item', function() {
      var item = $(this);
      var text = item.text();
      modal.show();
      modal.find('.modal-header').text('Are you sure you want to remove "' + text + '"?');
      $(document).on('click', '.modal-save', function() {
        item.remove();
        modal.hide();
      });
    });
  
    $(document).on('click', '.modal-close', function() {
      modal.hide();
    });
  
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.modal {
    display: none;
    background: rgba(0, 0, 0, 0.5);
  }
  
  .item-container {
    background: #eee;
    width: fit-content;
    padding: 10px;
  }
  
  .item {
    width: 100px;
    text-align: center;
    padding: 5px;
    border: 1px solid #ccc;
    margin: 5px 0;
    cursor: pointer;
  }
  
  .item:hover {
    background: #bbb;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="item-container"&gt;
    &lt;div class="item"&gt;one&lt;/div&gt;
    &lt;div class="item"&gt;two&lt;/div&gt;
    &lt;div class="item"&gt;three&lt;/div&gt;
    &lt;div class="item"&gt;four&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="modal" tabindex="-1" role="dialog"&gt;
    &lt;div class="modal-dialog" role="document"&gt;
      &lt;div class="modal-content"&gt;
        &lt;div class="modal-header"&gt;
          &lt;h5 class="modal-title"&gt;&lt;/h5&gt;
        &lt;/div&gt;
        &lt;div class="modal-footer"&gt;
          &lt;button type="button" class="btn modal-close"&gt;Cancel&lt;/button&gt;
          &lt;button type="button" class="btn modal-save"&gt;Confirm&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>