I have a form that I submit through ajax, and returns an updated chunk of html that includes an updated form that I want to submit through jquery.
The problem I am having is that the first time I click submit the event is captured by jquery and works great. When I make another change to the form without refreshing, the event is not captured by jquery, but makes a standard post request.
How can I have jquery attach behavior to an element after inserting it.
Here is my jquery code.
$('.edit_clothing_product').submit(function(){
var productDiv = $(this).parent();
var action = $(this).attr('action');
var formData = $(this).serialize();
$.post(action, formData, function(data){
productDiv.replaceWith(data);
});
return false;
});
Here is the (trimmed down) HTML that I return.
<div class="product">
<form action="..." class="edit_clothing_product">
<div class="color_combos">
...{form fields}
</div>
<a href=".../add_color_combo" class="add_color_combo">Add Color Combo</a>
<input name="commit" type="submit" value="Save" />
</form>
</div>