I've created an element that can be cloned multiple times. Each clone has a remove button that removes it from the DOM. I'm listening on a parent for the click on the cloned remove button but I only get the event for the original button. No event is detected for any other remove buttons.
To clone I use:
var $original = $(originalElementSelector);
$newCopy = $original.clone()
$original.after($newCopy);
My listener looks like this:
$(parentElement).on('click', '[data-clone-remove]', onRemoveClicked)
The original element is a descendant of the parent element. If I change it to $(document).on(...
then it works but it is listening for events from the whole document which is not what I want. The listeners are attached on document ready and the parent definitely exists at that point. The first remove button that exists on page load works as expected but no others do.
Any idea where I'm going wrong?