I have a page where some html is being dynamically added to the page.
This is the html and javascript that is created:
The problem in your code is that you are attaching the event to the button before the button is being created.
Correct version is:
Button
This should do the job.