There is a div, inside the field, the button is all in a separate html file (*)

There is a button, already on index.html, by clicking on which I execute: $.get is that separate file (*) html - when I click (like ajax but I don’t need the answer, so I use get) just pops up a window ( div) where the user clicks on the iiii button ....

Here, when I try to hang up the click handler on the button, a problem appears, since element of this is not initially in the DOM, those and id buttons (with a div that loads) and I can not process the data.

Is there a way out of this situation? or I have a very wrong approach? Well, those, I want to work out the php logic without reloading the page. HTML jq only.

If the handler had hung up on the newly appeared (loaded button) I would write there:

  $.post('./includes/delrow.php', {'idslist[]': ids}, function(data) { alert(data); location.reload(); } ); 

But the problem is that

 $('#new_btn').click(function() { ... } 

It does not work, because initially it is not in the DOM, it appears after the execution of $.get . Thanks in advance for your reply.

    2 answers 2

    For this, there is a .on example :

     <div id="test">Example:</div> $('#test').on('click','.ap',function(){ $(this).text('test'); }); $('#test').append('<span class="ap">*</span>'); 

    Clicking on * will update the text spana.

      replace

       $('#new_btn').click(function() { ... } 

      on

       $('body').on('click', '#new_btn', function() { ... } 

      and everything will work;)