0
$('.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.

Robert
  • 1,745
  • 5
  • 34
  • 61
  • 1
    `$('.my-existing-thing').on('click', '.my-generated-thing', function () { console.log('testing'); });` – 76484 Feb 28 '23 at 15:30

0 Answers0