diff --git a/field_collection.module b/field_collection.module
index 5692657..b8fd57f 100644
--- a/field_collection.module
+++ b/field_collection.module
@@ -1490,7 +1490,16 @@ function field_collection_remove_js() {
   // on a page. Unfortunately what it doesn't realize is that the IDs
   // we are generating are going to replace IDs that already exist, so
   // this actually works against us.
-  if (isset($_POST['ajax_html_ids'])) {
+  $ajax_html_ids = array();
+  if (!empty($_POST['ajax_html_ids'])) {
+    // ajax_html_ids might be a comma-separated string instead of a keyed array.
+    // See http://drupal.org/node/1575060 and drupal_html_id().
+    if (isset($_POST['ajax_html_ids'][0]) && strpos($_POST['ajax_html_ids'][0], ',') === FALSE) {
+      $ajax_html_ids = $_POST['ajax_html_ids'];
+    }
+    else {
+      $ajax_html_ids = explode(',', $_POST['ajax_html_ids'][0]);
+    }
     unset($_POST['ajax_html_ids']);
   }
 
@@ -1501,11 +1510,20 @@ function field_collection_remove_js() {
   $button = $form_state['triggering_element'];
   // Go two levels up in the form, to the whole widget.
   $element = drupal_array_get_nested_value($form, array_slice($button['#array_parents'], 0, -3));
+
+  // Check 'ajax_html_ids' to make sure we are using the correct ID.
+  $actual_id = $element['#id'];
+  foreach ($ajax_html_ids as $id) {
+    if ($id == $element['#id'] || strpos($id, $element['#id'] . '--') === 0) {
+      $actual_id = $id;
+      break;
+    }
+  }
   // Now send back the proper AJAX command to replace it.
   $return = array(
     '#type' => 'ajax',
     '#commands' => array(
-      ajax_command_replace('#' . $element['#id'], drupal_render($element))
+      ajax_command_replace('#' . $actual_id, drupal_render($element))
     ),
   );
 
