I have the form below which when I click on Add More Pet , it adds another panel
ButwhenIclickRemove,itremovesonlythebuttonsandthepanelscontinue.Lookatthecode:
<tableborder="0" style="width: 100%">
<tr class='linhas'>
<td>
<div class="panel panel-primary">
<div class="panel-heading">
<i class="fa fa-paw fa-lg" aria-hidden="true"></i> DADOS DO PET
</div>
<div class="panel-body">
<div class="table-responsive">
<div class="form-group">
<label>Espécie:</label>
<select name="Especie" class="form-control">
<option value="Canino">Canino</option>
<option value="Felino">Felino</option>
</select>
</div>
<div class="form-group">
<label>Nome do Pet:</label>
<input type="text" name="NomePet" class="form-control" required="required">
</div>
<div class="form-group">
<label>Aniversário do Pet:</label>
<input type="date" name="AniversarioPet" class="form-control" data-inputmask="'alias': '99/99/9999'" required="required">
</div>
<div class="form-group">
<label>Gênero:</label>
<div class="checkbox">
<label><input type="radio" name="SexoPet" value="Macho" checked> Macho</label>
<label><input type="radio" name="SexoPet" value="Fêmea"> Fêmea</label>
</div>
</div>
<div class="form-group">
<label>Idade:</label>
<select name="IdadePet" class="form-control">
<option value="Antes dos 11 meses">Antes dos 11 meses</option>
<option value="Entre 1 e 8 anos">Entre 1 e 8 anos</option>
</select>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td>
<button type="button" class="adicionarCampo btn btn-primary" title="Adicionar item"><i class="fa fa-plus-square" aria-hidden="true"></i> Adicionar mais Pet</button>
<button type="button" class="removerCampo btn btn-danger" title="Remover linha"><i class="fa fa-minus-square" aria-hidden="true"></i> Remover</button>
</td>
</tr>
</table>
JQUERY
<script type="text/javascript">
$(function () {
function removeCampo() {
$(".removerCampo").unbind("click");
$(".removerCampo").bind("click", function () {
if($("tr.linhas").length > 1){
$(this).parent().parent().remove();
}
});
}
$(".adicionarCampo").click(function () {
novoCampo = $("tr.linhas:first").clone();
novoCampo.find('input[type="text"]').val("");
novoCampo.find('select').val("");
novoCampo.insertAfter("tr.linhas:last");
removeCampo();
});
});
</script>
What I find strange, is when I put the line below inside a TD as another column where the panel is, it works:
<button type="button" class="removerCampo btn btn-danger" title="Remover linha"><i class="fa fa-minus-square" aria-hidden="true"></i> Remover</button>
How can I resolve this?