php - JQuery doesn't work with components loaded by $.post() -


i'am creating page load other page inside div, without refresh, template. components designed jquery-ajax request not interact function created me jquery, if selectors of these components not exist.

below creating function load page in center of template:

function carregaurl2(url) {      var data = $("form").serialize();      $.ajax({         type: "post",         url: url,         data: data     }).done(function(data) {         $("#divcentral").html(data);     });  } 

below function test, interact components created jquery-ajax request:

$(document).ready(function() {      $("form").change(function(e) {         alert("submit form");         e.preventdefault();          return false;      });      $("select").click(function() {         alert("input click");     });  }); 

i've searching solutions, has been hard!

could me, please?

the elements don't exist when ready function fires. need use delegate instead, allows binding objects created after handler registered.

$("#divcentral").on("click", "select", function() {     alert("input click"); }); 

.on() | jquery api documentation


Comments