$('.my-generated-thing').on('click', function() {
console.log('testing');
});
$('.my-existing-thing').on('click', function() {
$('.my-existing-thing').after('<button type="button" class="my-generated-thing">Now Click Me</button>');
});
<button type="button" class="my-existing-thing">Original Click Me</button>
What would be the best way to modify this such that the button generated by the .after call would result in 'testing' in the console after clicking? As I currently see it, it looks like you have to define the click event after the creation of the control, but would like to make it a bit cleaner if possible.