title: Drupal AJAX callback only getting called once
body: <p>I'm trying to make a form in Drupal, so more than one element can be added to a form. For example, a page might contain data for an event, then the event might have multiple dates. So I have a form that looks like:</p>
  
  <pre><code>/**
   * Implements hook_form_alter().
   */
  function addextra_form_alter(&amp;$form, &amp;$form_state) {
    if ($form['#form_id'] == 'test_content_node_form' ) {
      $form['elements_table'] = array(
          '#theme' =&gt; 'table',
          '#title' =&gt; 'Elements already added',
          '#header' =&gt; array('Item', 'Remove'),
          '#empty' =&gt; 'No elements',
          '#prefix' =&gt; '&lt;div id="elements-table"&gt;',
          '#suffix' =&gt; '&lt;/div&gt;',
      );
      $form['add_elements'] = array(
        '#title' =&gt; 'Add another element',
        '#type' =&gt; 'fieldset',
        '#collapsible' =&gt; TRUE,
        '#collapsed' =&gt; FALSE,
      );
      $form['add_elements']['add_content'] = array(
          '#type' =&gt; 'textfield',
          '#description' =&gt; t('Add an element to the table'),
          '#title' =&gt; t('Add another item'),
          '#size' =&gt; '12',
          '#maxlength' =&gt; '60',
          '#prefix' =&gt; '&lt;div id="addextra_content"&gt;',
          '#suffix' =&gt; '&lt;/div&gt;',
      );
      $form['add_elements']['add_another_btn'] = array(
          '#type' =&gt; 'button',
          '#name' =&gt; 'add_another',
          '#button_type' =&gt; 'submit',
          '#executes_submit_callback' =&gt; FALSE,
          '#value' =&gt; 'Add another',
          '#ajax' =&gt; array(
              'callback' =&gt; 'addextra_element_to_table',
          ),
      );
    }
  }
  </code></pre>
  
  <p>When 'add_another_btn' gets clicked, it will run the ajax callback 'addextra_element_to_table.</p>
  
  <p>That callback is:</p>
  
  <pre><code>function addextra_element_to_table(&amp;$form, &amp;$form_state) {
    $form['elements_table']['#rows'][] = array($form_state['values']['add_content'], l('Remove Item', '#'));
    drupal_add_js(drupal_get_path('module', 'addextra') . '/addextra.js');
    return array(
        '#type' =&gt; 'ajax',
        '#commands' =&gt; array(
            ajax_command_replace('#elements-table', render($form['elements_table'])),
  
        ),
    );
  }
  </code></pre>
  
  <p>The js file called replaces the val of the input field to ''</p>
  
  <pre><code>(function ($) {
    $('#edit-add-content').val('');
  })(jQuery);
  </code></pre>
  
  <p>But this callback only gets called one time. I believe this is because the behaviour has to be attached again once it's been called. Sorry for my ignorance - I'm not sure how to achieve this. Can anyone help me out? It would be much appreciated. Thanks in advance.</p>