3
I would like one of the automatically generated columns in the table to have a function to delete the row, but the on click is not working. How should I do it ?
$(document).ready(function(){
$("#associar1").on("click", function(e){
var coluna = "<tr>";
coluna += "<td width='40%' align='center'><input type='text' disabled = 'disabled' value= "+$("#canal").val()+" name='vigenciaCanalVendaVO.canalVendaVO.codigo'/></td>";
coluna +="<td width='40%' align='center'><input type='text' mask = '99/99/9999' disabled = 'disabled' data-mask='data' data-date-type='default' size='12' maxlength='10' value="+$("#dataInicioVigencia").val()+" name='vigenciaCanalVendaVO.dataInicioVigenciaAssociacaoPlano'/>"
coluna +="Até<input type='text' mask='99/99/9999' data-mask='data' disabled = 'disabled' data-date-type='default' size='12' maxlength='10' value="+$("#dataFimVigencia").val()+" name='vigenciaCanalVendaVO.dataFimVigenciaAssociacaoPlano'/></td>";
coluna +="<td align='center'><img src='/includes/images/bt_remover.gif' id='remover' style='cursor:pointer;cursor:hand;'/></td>";
coluna += "</tr>";
//alert(coluna);
($('#tabelaCanais')).append(coluna);
});
});
$("#remover").on("click",function(e){
$(this).parent().parent().remove();
});
Excellent your answer, I need to do the same thing only that after the execution of an Ajax, when I do outside Ajax works, but when I put inside the Ajax Success does not work, I have to modify something?
– Alan Almeida
@Alanalmeida works the same way. What is important is to ensure that the
.on()
is applied on an element that was already in the DOM. If you do not know the safest is to use$(document).on(...etc
– Sergio
@Alanalmeida if you can’t ask a question that you’ll have help solving.
– Sergio
posted a question on this link http://answall.com/questions/37748/executar-fun%C3%A7%C3%A3o-jquery-in-table-dynamically-ap%C3%B3s-a-ajax if you can take a look.
– Alan Almeida
Thank you very much, it worked perfectly.
– Bruno
@Alanalmeida now saw the question. Brasofilo’s answer is right. The
this
inside AJAX is not the same as outside, you have to use a reference typevat self = this;
or as he did there.– Sergio