const elementEditing = document.getElementById('example');
elementEditing.addEventListener("keydown", onkeydownInEditable);
function onkeydownInEditable(e, KeyboardEvent) {
if (e.key === "Enter") {
e.preventDefault();
}
if (e.key === "Backspace") {
console.log('is el[notContentDeletable] just in front cursor and will be deleted ?')
} else if ( e.key === "Delete") {
console.log('is el[notContentDeletable] just behind cursor and will be deleted ?')
}
}
<div id="example" contentEditable="true">
aaaaa 1<input notContentDeletable>2 bbbbb
</div>
I want to prevent that an element with [notContentDeletable] attribute gets deleted by "del" or "backspace".
(in jsfiddle)
if im between
1
andinput
and pressdel
the input will be deleted. I want to prevent this.if im between
input
and2
and pressbackspace
the input will be deleted. I want to prevent this.
So how can I get the element next to or after the cursor? Is that possible?