Add javascript to returned form after ajax validation I've built a form with the form API, and it's submitting via ajax via this type of thing:

  $form['submit'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; 'submit',
  '#ajax' =&gt; array(
      'callback' =&gt; 'handyman_form_callback',
      'method' =&gt; 'replace',
      'wrapper' =&gt; 'form-wrap',
      'effect' =&gt; 'fade'
  )
);


The problem is, if the form is returned due to validation errors the javascript applied to the form no longer works. I've read lots about the attachBehaviors function but I'm not sure where I could put this to make it work, and not sure if this is even the correct thing to do. 

Any help?
you can attach custom jQuery functions in your modules every time you load content just attaching functions to the Drupal.behaviors like this:

(function($) {

  Drupal.behaviors.your_module = {

    attach: function(context, settings){
      $('#element').bind('click', function(event){
            alert('hello!');
      });
    }

  }

}


In this way, every time Drupal loads content, no matter via ajax or a page refresh, it will automatically attach the desired behaviors. Don't forget to include the js in your pages.