Cannot access to selector of div that is created by jquery? -


i trying access selector created using html() of jquery function. tried many solutions few websites, doesn't work. now, make example, please correct , tell me reason

please see example here

    $(document).ready(function(){      $(".close").click(function(){      alert("message closed");    });    $("button").click(function(){     $("#msg").html('<div class="close">close</div><div>message...</div>');    }); 

thank much.

since close created dynamically, need use event delegation

$(document).ready(function () {     $('#msg').on('click', ".close", function () {         alert("message closed");     });     $("button").click(function () {         $("#msg").html('<div class="close">close</div><div>message...</div>');     }); }); 

demo: fiddle


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -