I have a page with input
, a button to add inputs
, and each has a corresponding button to remove it.
The problem is that I can not remove the inputs
added through the button. Only the original is removed. Follow the code here and running on jsfiddle
HTML:
<div id="content">
<button class="add">Adicionar outro campo</button>
<br><br>
<span>
<input type="text" name="nome" value="Original">
<button class="apagar">Apagar </button>
<br>
</span>
</div>
JS:
$(document).ready(function(){
$('.add').click(function(){
$('#content').append('<span> <input type="text" name="nome" value="Cópia"> <button class="apagar">Apagar </button></span> <br> ');
});
$('.apagar').click(function(){
$(this).parents('span').remove();
});
});