jQuery element remove only works on the second click

I am new to JavaScript, jQuery, Ajax and tried to remove element after delete. On first click element or elements removes and appears again. On the second click it's working fine, removes element or elements and they don't appear again. How to fix the first click? Where I am mistaken?

My code:

function confirmMassDelete() {
  if ($('input[name="checkbox[]"]:checked').length > 0) {
    var agree = confirm("Are you sure you want to mass delete?");
    var id = [];
    $(':checkbox:checked').each(function(i) {
      id[i] = $(this).val();
    });
    if (agree) {
      $.ajax({
        url: "list.php",
        method: "POST",
        data: {
          id: id
        },
        success: function(response) {
          for (var i = 0; i < id.length; i++) {
            $('div#' + id[i] + '').remove();
          }
        }
      });
      return true;
    } else {
      return false;
    }
  } else {
    alert("Please select products to delete.");
    return false;
  }
}
<button id="apply" name="apply" type="submit" disabled class="btn btn-primary" onclick="return confirmMassDelete();">Apply</button>