javascript - jQuery not recognizing selectors created by the .html() method -
this question has answer here:
i'm trying create dynamic content box. when click 1 button, box's content changes .html(). when click another, content changes again.
this fine, created within box doesn't seem selectable.
so example:
$(document).ready(function(){ boxcontent1 = "<div class='studyselector'></div>"; $("#casestudy").on('click',function(){ $("#botbox").hide().html(casestudy).fadein(1000); }); });
in case, content of #botbox changes fine. however, when try interact it
$(".studyselector").on('click',function(){ alert("testing!"); });
nothing happens. why happening?
you have use event-delegation dynamically create nodes in dom after rendering:
$('#botbox').on('click', '.studyselector',function(){ alert("testing!"); });
should working.
Comments
Post a Comment