What is the correct way to bind an event to an appended element?
I'm doing it like this (and it is working):
$('#element').on('click', function( event ) {
$('#anything').append('<div class="delete"></div>');
$('.delete').on('click', function( event ) {
$(this).remove();
});
});
Or should I use a delegated on()
for the click on delete event outside of the first on()
?