AJAX added fields don't hide I have a altered registration form with a check box that when checked adds few fields. The fields are wrapped in a specific div.

The callback function of check box is supposed to hide the dive when the check box is unchecked. 

The adding works well but the unchecking doesn't. If I uncheck the checkbox the added fields remain there as nothing has happened. Checking it again doesn't change anything.

The weird thing is that the div is there (at least Firefox inspector sees it) and the callback function is probably fired as well (the POST is send).

I have even tried to debug it using dsm() but it doesn't show any message (no idea why).

    function fm_users_more_form_user_register_form_alter(&amp;$form, &amp;$form_state, $form_id) {

  $form['fm_first_in_firm'] = array(
    '#type' =&gt; 'checkbox',
    '#title' =&gt; t('Show form.'),
    '#ajax' =&gt; array(
      'callback' =&gt; '_fm_ajax_new_firm_form',
      'wrapper' =&gt; 'firm-reg-container-div',
      'method' =&gt; 'replace',
      'effect' =&gt; 'fade',
    ),
  );

  $form['firm_registration_container'] = array(
    '#type' =&gt; 'hidden',
    '#attributes' =&gt; array('id' =&gt; array('firm-reg-container-div')),
  );
}


function _fm_ajax_new_firm_form($form, &amp;$form_state) {
  if ($form['fm_first_in_firm']['#value'] == 1) {    
    dsm('tst1');

    ...

    $firm_form = drupal_get_form('fm_firm_node_form', $node);

    $form_wrapped = array(
      '#prefix' =&gt; '&lt;div class="firm-reg-container-div"&gt;',
      '#suffix' =&gt; '&lt;/div&gt;',
    );  

    $form_wrapped['register_form'] = $firm_form;
    return $form_wrapped;
  }
  else {
    dsm('tst2');
    return array(
      '#type' =&gt; 'hidden',
      '#attributes' =&gt; array('id' =&gt; array('firm-reg-container-div')),
    );
  }
}
To show or hide some form elements you can use #states attribute.

$form['fm_first_in_firm'] = array(
  '#type' =&gt; 'checkbox',
  '#title' =&gt; t('Show form.')
);

$form['firm_registration_container'] = array(
  '#type' =&gt; 'item',
  '#attributes' =&gt; array('id' =&gt; array('firm-reg-container-div')),
  // make this form item visible only if "fm_first_in_firm" is checked
  '#states' =&gt; array(
    'visible' =&gt; array(
      ':input[name="fm_first_in_firm"]' =&gt; array('checked' =&gt; TRUE)
    )
  )
);