1
Hello I have a registration screen of academic information; I need that field can be duplicated and removed, but when I remove only the first DIV and deleted; I use the javascrip below, when the person clones the field appears the 'X' to delete, but if it duplicates more than once the last 'X' will delete the first field, no matter 'X' will always remove the first field.
HTML:
<div id="academico" class="tab-pane fade">
<div id="academico1">
<div class="col-xs-9">
<label for="ex3">Formação</label>
<input class="form-control input-sm" title="Digite o nome do curso" id="FormacaoAcademica" name="estudo[]" type="text" >
</div>
<div class="col-xs-3">
<label for="ex3">Status</label>
<select class="form-control input-sm" id="FormacaoAcademica" name="estudo[]" >
<option selected disabled>Selecione</option>
<option>Cursando</option>
<option>Concluido</option>
</select>
</div>
<div class="col-xs-9">
<label for="ex3">Nível</label>
<input class="form-control input-sm" title="Especifique se o curso trata-se de curso tecnico, graduação ou pos-graduação" name="estudo[]" type="text" id="FormacaoAcademica">
</div>
<div class="col-xs-3">
<label for="ex3">Ano de conclusão</label>
<input class="form-control input-sm" title="Digite o Ano de Conclusão" name="estudo[]" type="text" id="FormacaoAcademica">
</div>
<div class="col-xs-3" id="botoesacademico">
<a class="hidden" href="javascript:void(0)" id="btnova_tarefa" onclick="Removeacademico()" title="Remover"><img src="imagens/rem.png"/></a>
</div>
<hr style="clear:both;">
</div>
<center><a class="inline" href="javascript:void(0)" id="btnova_tarefa" onclick="Clonaacademico()" title="Adicionar"><img src="imagens/add.png"/></a></center>
</div>
javascrip to Clone:
function Clonaacademico() { $("#academico1").clone().fadeIn(700).insertBefore($("#academico1")).find('#FormacaoAcademica').val('');
document.getElementById("btnova_tarefa").setAttribute("class", "inline");
count = count + 1;}
Javascrip to delete:
function Removeacademico() {
$('#academico div#academico1:this').fadeOut(700, function () {
$('#academico div#academico1:this').remove();
});}
Thank you very much sam, helped very much was breaking my head with this, thanks also for the tips, I am very much Noob still in javascrip and I am involved in some projects that this difficult to study.
– Higor Bandeira
Hello, what developed helped a lot, but I had some problems with Jquery, as you used version 2.1.1, I changed in my program, but other functions did not work, would have some hint, I used version 1.3.2
– Higor Bandeira
Man, thank you very much, but I managed to solve it here; I believe it is not the best way, but for now it solves. $("#btdel_task"). live('click', Function() { var div = $(this). Closest('#academico1'); div.fadeOut(700, Function() { div.remove(); }); });
– Higor Bandeira