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?
Event listener
keydown
can be added to that<div contenteditable>
element.Keydown
andkeypress
events takes place before the content is changed andevent.preventDefault()
can be used to stop the content before editing.Is this what you want?