tags:

views:

20

answers:

1

I am using jQuery form plugin and it is working great. Now I am loading a form using ajax. On success callback I have code something like this

success: function(data) {
  $('#container').prepend(data);
  ajaxify_form();
}

var ajaxify_form = function() {
    $('.new_form').ajaxForm(options);
};

I need to do all that because I could not make jquery form work with 'live'.

Am I doing something wrong. Is there a better way to bind a form which was loaded through ajax so that I do not need to explicitly bind in every success callback.

A: 

Somewhat similar to my answer here: http://stackoverflow.com/questions/3840149/jquery-live-event-for-added-dom-elements/3840307#3840307.

Use the livequery() plugin and do it once. It will trigger for both existing and new forms added to the DOM.

$('.ajax_form').livequery(function() {
  //use $(this) to apply form plugin   
});
Gregg
keep forgetting that livequery is stil available as a tool. Yes livequery will work excellent in this case. Thank you.
Nadal