I have a code chunk of html:
<div id="chunk-1" class="chunk">
<div class="chunkText">Text<div>
<button class="addChunk">Click Me</button>
</div>
<script>
$(".addChunk").click(function(){create_chunk(this.parentNode)})
function create_chunk(after_this){
$(after_this).after(chunk_html)
var i = 0
$("div.chunk").each(function(){$(this).attr('id', "chunk-" + i++)})
}
</script>
Now, this works, but only for the .chunk that is statically rendered on the page. When I press the button a second chunk appears, but that button does not work. If I add the html for two or more chunks to be rendered, each one works, but the buttons for the chunks it creates do not. What should I do?