The issue with detecting and using id within replaceWith or new HTML code
Hi, I'm having an issue with replaceWith. When I click on the div below and replace the HTML. I am not able to use the id within the new div. I even tried HTML instead of replaceWith and I am still not able to.
<div id="action"></div>
<script>
$("#action").click(function(){
var foo = $(this).attr('id');
//$("#"+foo).html("<div id="next">do this</div>");
$("#"+foo).replaceWith("<div id="next">do this</div>");
});
$("#next").click(function(){
var bar = $(this).attr('id');
alert(bar);
});
</script>