Html: Contenteditable how to detect before deleting element after pressing backspace?

I am making a text editor with <div contenteditable>. I want to prompt a confirmation message before the user deleting image element inside the editor. So when the user press backspace, before deleting the image element, there should be a prompt "Are you sure you want to delete the image?".

How can I do this?

18 thoughts on “Html: Contenteditable how to detect before deleting element after pressing backspace?”

Leave a Comment