I am creating a form with a dynamic number of options. Deleting options works fine for those items that are existing from the start, but the items that are generated dynamically cannot be removed. Anyone have a clue?
JSFiddle: http://jsfiddle.net/Kxr4C/
HTML:
<div class="options">
<div><input type="text" name="option[]" value="Option A"> <a href="#" class="delete_option">Delete</a></div>
<div><input type="text" name="option[]" value="Option B"> <a href="#" class="delete_option">Delete</a></div>
<div><input type="text" name="option[]" value="Option C"> <a href="#" class="delete_option">Delete</a></div>
</div>
<a href="#" class="new_option">Add a new option</a>
Javascript:
jQuery('a.new_option').click(function(){
jQuery('div.options').append('<div><input type="text" name="option[]" value=""> <a href="#" class="delete_option">Delete</a></div>');
});
jQuery('a.delete_option').click(function(){
jQuery(this).parent('div').fadeOut();
});