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
Post a Comment