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
1andinputand pressdelthe input will be deleted. I want to prevent this. -
if im between
inputand2and pressbackspacethe 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?
from get element just in front or after the cursor
No comments:
Post a Comment