Jquery with dynamic html code

0

I have a function in Ajax that when added, inserts / updates a .php page

 $("#recarrega-adt").click(function(event) {
   $.ajax({
                 url       : 'classes/consulta-aditivo.php',

            success : function(txt){
                 $('#view-full-adt').load('classes/consulta-aditivo.php');
            },
            error: function(result) {
                alert("Erro");
                /*sweet alert*/
            }
  });
 }); 

The problem that when this action is taken the other JS / Jquery functions stop working because this code was inserted "after" the rest was executed. How should I solve this problem? I found the method live() and on() , but both did not have effects ... The only way I found was leaving the method on the same page that is called but would not like to do that = /

Thank you in advance.

$(document).ready(function(){
$(".option-aditivo h3").on("click",function(){
    alert('teste');
    var id = this.id;
    var frase = this.title;
    $("<span class='frase-aditivo mover' id='adt"+id+"-enable'>"+frase+"</span>").appendTo("#papel");

    $(this).removeAttr('id')
    $(this).attr('id',id+"-plus");
    Draggable.create("[id*=adt]");
  });
 });
    
asked by anonymous 16.06.2016 / 14:19

1 answer

0

Instead of using this:

$(document).ready(function(){
    $(".option-aditivo h3").on("click",function(){
        alert('teste');
        var id = this.id;
        var frase = this.title;
        $("<span class='frase-aditivo mover' id='adt"+id+"-enable'>"+frase+"</span>").appendTo("#papel");
        $(this).removeAttr('id')
        $(this).attr('id',id+"-plus");
        Draggable.create("[id*=adt]");
   });
});

Try asim:

$(document).ready(function(){
    $(document).on("click", ".option-aditivo h3", function(){
        alert('teste');
        var id = this.id;
        var frase = this.title;
        $("<span class='frase-aditivo mover' id='adt"+id+"-enable'>"+frase+"</span>").appendTo("#papel");
        $(this).removeAttr('id')
        $(this).attr('id',id+"-plus");
        Draggable.create("[id*=adt]");
   });
});
    
16.06.2016 / 22:40