I have a form that has multiple instances of the same field set. You can add more field sets by clicking "Add a Field."
The page starts with 5 field sets. If you click "Remove," the background color will change to red (so that you can tell which field set would be removed).
If you add more fields, those field sets will not respond to the "Remove" button even though they have the exact same code as the ones that the page starts out with, and they are added to the same form.
Can you please take a look at my code and let me know why the added fields will not remove whereas the ones that start out on the page remove?
https://jsfiddle.net/Lc510xmn/1/
// Adds a new field set to the form
$('[data-action="addField"]').click(function(){
var fieldSet = '<fieldset><input type="text" name="field"><button type="button" data-action="removeField">Remove</button></fieldset>';
$('form').append(fieldSet);
return false;
});
// Changes the background to red instead of removing
$('[data-action="removeField"]').click(function(){
$(this).parents('fieldset').css('background-color','red');
return false;
});