Backspace removes the entire span element

Is it possible to prevent span removal using backspace?

<div class="form-control" contenteditable="true">
  <span class="correct-answer">
    <span contenteditable="false">The correct answer is (A) 1 to 2. </span>
    <span class="sentence" num="11">dgsdgsg. sgsdgs sgsgs.</span>
  </span>
</div>
Run codeHide result

Example: http://jsfiddle.net/pvj64px9/1/

The correct answer is (B) 2 to 3. and `Choice A (1 to 2) is incorrect. ` must not be deleted.
+4
source share
1 answer

update the parent container to have contenteditable = "false"

<div id="window-kitkat" class="form-control" contenteditable="false">

and set the individual elements you want to change, for example,

<span class="sentence" num="10" contenteditable="true">jfbgfdgdf sgdsgsd.</span>
+1
source

Source: https://habr.com/ru/post/1607918/


All Articles