onclick - Jquery click doesn't work on append -


i'm trying use jquery .click on div append, click doesn't work @ all. here code, tried other tutorials find on internet didn't work.

here jquery (very simple version) :

$(document).ready(function() { $( "#divresult" ).click(function() {      alert('yolo');  //$( "#return" ).submit(); }); }); 

and way create divresult ajax , append :

$(document).ready(function () {     $('#monform').on('submit', function (e) {         e.preventdefault();         var $this = $(this);         var adrall = $('#villedepart').val();         var adrarr = $('#villearrivee').val();         var datedepart = $('#datedepart').val();         var nombreplace = $('#nombreplace').val();         $.getjson('/app.php/recht/refresh', {data: adrall + ' , ' + adrarr + ' , ' + datedepart + ' , ' + nombreplace}         ).done(function (res) {             console.log(res);             $("#resultcontainer").html("");             if (res == "") {                 secondchoix();                 tiercechoix();             }             else {                 $.each(res, function (ligne, result) {                     var resultats =                             "<div class=" + '"output container col-lg-8 blueskycont col-lg-offset-2"' + ' id="divresult"'+                              ">" + " <form name=" + '"retour"' + " action=" +                             '"/app.php/validationdemande/go"' + "role=" + '"form"' + " method=" + '"post"' + " class=" + '"retour"' + ' id="return"'+                             "> <div class=" + '"form-group col-lg-12 col-md-12 col-xs-sm-12 col-xs-12"' + ">" +                             "<label class=" + '"funzies col-lg-12 col-md-12 col-xs-sm-12 col-xs-12 move"' + " for=" + '"pwababd"' + ">" + result.traj_lieu_dep + " -> " + result.traj_lieu_arr + "</label>" +                             " <label class=" + '"funzies col-lg-12 col-md-12 col-xs-sm-12 col-xs-12"' + "> départ le : " + result.traj_date + "</label> " +                             " <label class=" + '"funzies col-lg-12 col-md-12 col-xs-sm-12 col-xs-12"' + "> de : " + result.prot_lieu_dep + "</label> " + "</br>" +                             " <label class=" + '"funzies col-lg-12 col-md-12 col-xs-sm-12 col-xs-12"' + "> " + result.prot_lieu_arr + "</label> " + "</br>" +                             " <label class=" + '"funzies col-lg-12 col-md-12 col-xs-sm-12 col-xs-12"' + "> : " + result.traj_nb_place + " places restante(s) </label> " + "</br>" +                             "<label class=" + '"funzies col-lg-2 col-md-2 col-xs-sm-2 col-xs-2"' + "> " + result.prof_prenom + " " + result.prof_nom + " </label> " +                             "<input type=" + '"hidden" class="" id="" name="prot_id" value="' + result.prot_id + '">' +                             "<input type=" + '"hidden" class="" id="" name="prot_red" value="' + result.prot_red + '">' +                             "<input type=" + '"hidden" class="" id="" name="traj_type" value="' + result.traj_type + '">' +                             "<input type=" + '"hidden" class="" id="" name="ville_dep" value="' + result.traj_lieu_dep + '">' +                             "<input type=" + '"hidden" class="" id="" name="ville_arr" value="' + result.traj_lieu_arr + '">' +                             "<input type=" + '"hidden" class="" id="" name="lieu_dep" value="' + result.prot_lieu_dep + '">' +                             "<input type=" + '"hidden" class="" id="" name="lieu_arr" value="' + result.prot_lieu_arr + '">' +                             "<input type=" + '"hidden" class="" id="" name="nombreplace" value="' + nombreplace + '">' +                             "<input type=" + '"hidden" class="" id="" name="demande_ville_dep" value="' + adrall + '">' +                             "<input type=" + '"hidden" class="" id="" name="demande_ville_arr" value="' + adrarr + '">' +                             "</div>  </form> </div>";                      $("#resultcontainer").append(                             resultats                             );                 });             }         })                 .fail(function (res) {                     alert('fail');                           })                 .error(function (res) {                     alert('erreur');                 });     }); }); 

i'm trying use submit since : onclick="document.forms[\'retour\'].submit();" doesn't work on ie.

but clic not respond @ on divresult. mean can't use jquery.click on div append?

you need event delegation!

$("#resultcontainer").on("click", "#divresult", function() {  }); 

handlers bound @ runtime - , since elements don't exist then, no handlers bound. check #resultcontainer each click #divresult , run handler if found.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -